[dia] [warningectomy] Handle return value of write()
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [warningectomy] Handle return value of write()
- Date: Sun, 28 Nov 2010 18:23:46 +0000 (UTC)
commit b6676a5bfe07eb86ddc34a5133f5be6ad159874d
Author: Hans Breuer <hans breuer org>
Date: Sat Nov 27 18:26:22 2010 +0100
[warningectomy] Handle return value of write()
Instead of:
dia_xml.c: In function 'xml_file_check_encoding':
dia_xml.c:211..215,220: warning: ignoring return value of 'write',
declared with attribute warn_unused_result
lib/dia_xml.c | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/lib/dia_xml.c b/lib/dia_xml.c
index c4927dd..d7859a1 100644
--- a/lib/dia_xml.c
+++ b/lib/dia_xml.c
@@ -116,6 +116,7 @@ xml_file_check_encoding(const gchar *filename, const gchar *default_enc)
gchar *tmp,*res;
int uf;
gboolean well_formed_utf8;
+ int write_ok;
static char magic_xml[] =
{0x3c,0x3f,0x78,0x6d,0x6c,0x00}; /* "<?xml" in ASCII */
@@ -208,20 +209,26 @@ xml_file_check_encoding(const gchar *filename, const gchar *default_enc)
res = g_strconcat(tmp,G_DIR_SEPARATOR_S,"dia-xml-fix-encodingXXXXXX",NULL);
uf = g_mkstemp(res);
- write(uf,buf,p-buf);
- write(uf," encoding=\"",11);
- write(uf,default_enc,strlen(default_enc));
- write(uf,"\" ",2);
- write(uf,p,pmax - p);
-
- while (1) {
+ write_ok = (uf > 0);
+ write_ok = write_ok && (write(uf,buf,p-buf) > 0);
+ write_ok = write_ok && (write(uf," encoding=\"",11) > 0);
+ write_ok = write_ok && (write(uf,default_enc,strlen(default_enc)) > 0);
+ write_ok = write_ok && (write(uf,"\" ",2) > 0);
+ write_ok = write_ok && (write(uf,p,pmax - p) > 0);
+
+ while (write_ok) {
len = gzread(zf,buf,BUFLEN);
if (len <= 0) break;
- write(uf,buf,len);
+ write_ok = write_ok && (write(uf,buf,len) > 0);
}
gzclose(zf);
- close(uf);
+ if (uf > 0)
+ close(uf);
g_free(buf);
+ if (!write_ok) {
+ g_free(res);
+ res = NULL;
+ }
return res; /* caller frees the name and unlinks the file. */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]