diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/copy.c | 6 | ||||
-rw-r--r-- | src/shared/copy.h | 1 | ||||
-rw-r--r-- | src/shared/util.c | 21 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
4 files changed, 18 insertions, 12 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c index 4dfc2f3fca..4c227c8bee 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -22,7 +22,7 @@ #include "util.h" #include "copy.h" -static int stream_bytes(int fdf, int fdt) { +int copy_bytes(int fdf, int fdt) { assert(fdf >= 0); assert(fdt >= 0); @@ -92,7 +92,7 @@ static int fd_copy_regular(int df, const char *from, const struct stat *st, int return -errno; } - r = stream_bytes(fdf, fdt); + r = copy_bytes(fdf, fdt); if (r < 0) { unlinkat(dt, to, 0); return r; @@ -273,7 +273,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) { if (fdt < 0) return -errno; - r = stream_bytes(fdf, fdt); + r = copy_bytes(fdf, fdt); if (r < 0) { unlink(to); return r; diff --git a/src/shared/copy.h b/src/shared/copy.h index 5b569543ee..8fb057fe86 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -23,3 +23,4 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode); int copy_tree(const char *from, const char *to); +int copy_bytes(int fdf, int fdt); diff --git a/src/shared/util.c b/src/shared/util.c index 91cbf20454..a7aec5c54f 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; +} diff --git a/src/shared/util.h b/src/shared/util.h index 0f8c393353..1796014f26 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -946,3 +946,5 @@ int update_reboot_param_file(const char *param); int umount_recursive(const char *target, int flags); int bind_remount_recursive(const char *prefix, bool ro); + +int fflush_and_check(FILE *f); |