From 5f5b342dbd14a76290ef758292eee40e3df6d2ee Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 18 Oct 2001 21:10:04 +0000 Subject: Bumped the version number to 0.15.99.1. 2001-10-18 Christopher James Lahey * configure.in: Bumped the version number to 0.15.99.1. * gal/util/e-util.c, gal/util/e-util.h (e_write_file_mkstemp): New function to create a unique file. (e_write_file): Check the return value of close here. svn path=/trunk/; revision=13772 --- e-util/e-util.c | 32 +++++++++++++++++++++++++++++++- e-util/e-util.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3