From cb227b68b34052c2198cddfece3ee6da81a5e13e Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Tue, 23 May 2000 10:27:16 +0000 Subject: Added e_write_file. 2000-05-23 Christopher James Lahey * e-util.c, e-util.h: Added e_write_file. svn path=/trunk/; revision=3181 --- e-util/ChangeLog | 4 ++++ e-util/e-util.c | 26 ++++++++++++++++++++++++++ e-util/e-util.c-8611 | 26 ++++++++++++++++++++++++++ e-util/e-util.h | 1 + e-util/e-util.h-29002 | 1 + 5 files changed, 58 insertions(+) (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 2c0ed89a7c..ffad50d570 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,7 @@ +2000-05-23 Christopher James Lahey + + * e-util.c, e-util.h: Added e_write_file. + 2000-05-19 Federico Mena Quintero * e-dialog-widgets.[ch]: New files with utilities for hooking up diff --git a/e-util/e-util.c b/e-util/e-util.c index fd167599df..cac850b0d5 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -133,3 +133,29 @@ e_read_file(const char *filename) g_list_free(lengths); return ret_val; } + +gint +e_write_file(const char *filename, const char *data, int flags) +{ + int fd; + int length = strlen(data); + int bytes; + fd = open(filename, flags, 0666); + 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; + } + } + } + close(fd); + return 0; +} diff --git a/e-util/e-util.c-8611 b/e-util/e-util.c-8611 index fd167599df..cac850b0d5 100644 --- a/e-util/e-util.c-8611 +++ b/e-util/e-util.c-8611 @@ -133,3 +133,29 @@ e_read_file(const char *filename) g_list_free(lengths); return ret_val; } + +gint +e_write_file(const char *filename, const char *data, int flags) +{ + int fd; + int length = strlen(data); + int bytes; + fd = open(filename, flags, 0666); + 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; + } + } + } + close(fd); + return 0; +} diff --git a/e-util/e-util.h b/e-util/e-util.h index fef56c0531..132c89e9a0 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -40,5 +40,6 @@ void e_free_object_list (GList *list); void e_free_string_list (GList *list); char *e_read_file (const char *filename); +gint e_write_file(const char *filename, const char *data, int flags); #endif /* _E_UTIL_H_ */ diff --git a/e-util/e-util.h-29002 b/e-util/e-util.h-29002 index fef56c0531..132c89e9a0 100644 --- a/e-util/e-util.h-29002 +++ b/e-util/e-util.h-29002 @@ -40,5 +40,6 @@ void e_free_object_list (GList *list); void e_free_string_list (GList *list); char *e_read_file (const char *filename); +gint e_write_file(const char *filename, const char *data, int flags); #endif /* _E_UTIL_H_ */ -- cgit v1.2.3