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 0df0b71..d406613 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 af1f2fe..11ddd7d 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)
 {