diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-util.c | 32 | ||||
-rw-r--r-- | e-util/e-util.h | 2 |
2 files changed, 33 insertions, 1 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c index b209aa7dde..914c97c47a 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -195,7 +195,37 @@ e_write_file(const char *filename, const char *data, int flags) } } } - close(fd); + if (close(fd) != 0) { + return errno; + } + return 0; +} + +gint +e_write_file_mkstemp(char *filename, const char *data) +{ + int fd; + int length = strlen(data); + int bytes; + fd = mkstemp (filename); + if (fd == -1) + return errno; + while (length > 0) { + bytes = write(fd, data, length); + if (bytes > 0) { + length -= bytes; + data += bytes; + } else { + if (errno != EINTR && errno != EAGAIN) { + int save_errno = errno; + close(fd); + return save_errno; + } + } + } + if (close(fd) != 0) { + return errno; + } return 0; } diff --git a/e-util/e-util.h b/e-util/e-util.h index f7b2bf7a3c..666dc62320 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -81,6 +81,8 @@ char *e_read_file (cons int e_write_file (const char *filename, const char *data, int flags); +int e_write_file_mkstemp (char *filename, + const char *data); int e_mkdir_hier (const char *path, mode_t mode); |