Code

utils unixsock: Added wrappers for clearerr(), feof(), and ferror().
authorSebastian Harl <sh@tokkee.org>
Tue, 11 Dec 2012 09:58:13 +0000 (10:58 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 11 Dec 2012 09:58:13 +0000 (10:58 +0100)
src/include/utils/unixsock.h
src/utils/unixsock.c

index 0df0b71a3da6526dec090b489e6cbc9189eaba4a..d40661390d99bd466357c585eeccd2c83390a8a7 100644 (file)
@@ -62,6 +62,19 @@ sc_unixsock_client_recv(sc_unixsock_client_t *client, char *buffer, size_t bufle
 int
 sc_unixsock_client_shutdown(sc_unixsock_client_t *client, int how);
 
+/*
+ * sc_unixsock_client_clearerr, sc_unixsock_client_eof,
+ * sc_unixsock_client_error:
+ * Check and reset the client status. See the clearerr(3), feof(3), and
+ * ferror(3) manpages for details.
+ */
+void
+sc_unixsock_client_clearerr(sc_unixsock_client_t *client);
+int
+sc_unixsock_client_eof(sc_unixsock_client_t *client);
+int
+sc_unixsock_client_error(sc_unixsock_client_t *client);
+
 void
 sc_unixsock_client_destroy(sc_unixsock_client_t *client);
 
index af1f2fedaf4c6c5bd9c7fb253a0ce8baf856982f..11ddd7d7b2545be3ec686d8dcb8d6c496045de3f 100644 (file)
@@ -200,6 +200,34 @@ sc_unixsock_client_shutdown(sc_unixsock_client_t *client, int how)
        return status;
 } /* sc_unixsock_client_shutdown */
 
+void
+sc_unixsock_client_clearerr(sc_unixsock_client_t *client)
+{
+       if ((! client) || (! client->fh))
+               return;
+       clearerr(client->fh);
+} /* sc_unixsock_client_clearerr */
+
+int
+sc_unixsock_client_eof(sc_unixsock_client_t *client)
+{
+       if ((! client) || (! client->fh)) {
+               errno = EBADF;
+               return -1;
+       }
+       return feof(client->fh);
+} /* sc_unixsock_client_eof */
+
+int
+sc_unixsock_client_error(sc_unixsock_client_t *client)
+{
+       if ((! client) || (! client->fh)) {
+               errno = EBADF;
+               return -1;
+       }
+       return ferror(client->fh);
+} /* sc_unixsock_client_error */
+
 void
 sc_unixsock_client_destroy(sc_unixsock_client_t *client)
 {