[gnet] examples: don't ignore return value of fwrite()
- From: Tim-Philipp Müller <tpm src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnet] examples: don't ignore return value of fwrite()
- Date: Fri, 17 Apr 2009 16:03:07 -0400 (EDT)
commit b8ed92877ef85471a6447abd96e6cc182e8c3430
Author: Tim-Philipp Müller <tim centricular net>
Date: Fri Apr 17 20:50:35 2009 +0100
examples: don't ignore return value of fwrite()
---
examples/echoclient-async.c | 5 ++++-
examples/echoclient-gconn.c | 5 ++++-
examples/echoclient-udp.c | 5 ++++-
examples/echoclient-unix.c | 5 ++++-
examples/echoclient.c | 5 ++++-
examples/echoserver-unix.c | 9 +++++++--
examples/echoserver.c | 5 ++++-
examples/hfetch.c | 5 ++++-
8 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/examples/echoclient-async.c b/examples/echoclient-async.c
index 7f8b6bc..2efad48 100644
--- a/examples/echoclient-async.c
+++ b/examples/echoclient-async.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -149,7 +150,9 @@ async_client_sin_iofunc (GIOChannel* iochannel, GIOCondition condition,
{
gint i;
- fwrite (buffer, 1, bytes_read, stdout);
+ if (fwrite (buffer, 1, bytes_read, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
for (i = 0; i < bytes_read; ++i)
if (buffer[i] == '\n')
diff --git a/examples/echoclient-gconn.c b/examples/echoclient-gconn.c
index 4bc3064..f8419b7 100644
--- a/examples/echoclient-gconn.c
+++ b/examples/echoclient-gconn.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -155,7 +156,9 @@ ob_conn_func (GConn* conn, GConnEvent* event, gpointer user_data)
{
/* Write line out */
event->buffer[event->length - 1] = '\n';
- fwrite (event->buffer, event->length, 1, stdout);
+ if (fwrite (event->buffer, event->length, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
/* Check if done */
lines_pending--;
diff --git a/examples/echoclient-udp.c b/examples/echoclient-udp.c
index aa83bc2..31cfd47 100644
--- a/examples/echoclient-udp.c
+++ b/examples/echoclient-udp.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -81,7 +82,9 @@ main(int argc, char** argv)
if (n == -1) break;
/* Write out */
- fwrite (buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
gnet_inetaddr_delete (addr);
diff --git a/examples/echoclient-unix.c b/examples/echoclient-unix.c
index e970e2a..c2c2e1b 100644
--- a/examples/echoclient-unix.c
+++ b/examples/echoclient-unix.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -106,7 +107,9 @@ normal_echoclient(gchar* path, gboolean abstract)
e = gnet_io_channel_readn(iochannel, buffer, n, &n);
if (e != G_IO_ERROR_NONE)
break;
- fwrite(buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
if (e != G_IO_ERROR_NONE)
diff --git a/examples/echoclient.c b/examples/echoclient.c
index 3813a8f..1715473 100644
--- a/examples/echoclient.c
+++ b/examples/echoclient.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -102,7 +103,9 @@ main(int argc, char** argv)
error = gnet_io_channel_readn (iochannel, buffer, n, &n);
if (error != G_IO_ERROR_NONE) break;
- fwrite(buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
if (error != G_IO_ERROR_NONE)
diff --git a/examples/echoserver-unix.c b/examples/echoserver-unix.c
index e97c138..1bd0138 100644
--- a/examples/echoserver-unix.c
+++ b/examples/echoserver-unix.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <glib.h>
@@ -119,7 +120,9 @@ normal_echoserver(gchar *path, gboolean abstract)
e = gnet_io_channel_writen(ioclient, buffer, n, &n);
if (e != G_IO_ERROR_NONE)
break;
- fwrite(buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
if (e != G_IO_ERROR_NONE)
fprintf(stderr,
@@ -260,7 +263,9 @@ async_client_iofunc(GIOChannel *iochannel, GIOCondition c,
async_client_iofunc,
cs);
}
- fwrite(&cs->buffer[cs->n], bytes_read, 1, stdout);
+ if (fwrite(&cs->buffer[cs->n], bytes_read, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
cs->n += bytes_read;
}
}
diff --git a/examples/echoserver.c b/examples/echoserver.c
index b666509..ace965b 100644
--- a/examples/echoserver.c
+++ b/examples/echoserver.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -96,7 +97,9 @@ main(int argc, char** argv)
{
error = gnet_io_channel_writen(ioclient, buffer, n, &n);
if (error != G_IO_ERROR_NONE) break;
- fwrite(buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
if (error != G_IO_ERROR_NONE)
diff --git a/examples/hfetch.c b/examples/hfetch.c
index bbf8097..197d9b9 100644
--- a/examples/hfetch.c
+++ b/examples/hfetch.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <glib.h>
#include <gnet.h>
@@ -153,7 +154,9 @@ hfetch(gchar* server, gint port, gchar* filename)
if (n == 0)
break;
- fwrite(buffer, n, 1, stdout);
+ if (fwrite(buffer, n, 1, stdout) != 1) {
+ fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
+ }
}
gnet_tcp_socket_delete(socket);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]