From: Sebastian Harl Date: Tue, 11 Dec 2012 09:58:13 +0000 (+0100) Subject: utils unixsock: Added wrappers for clearerr(), feof(), and ferror(). X-Git-Tag: sysdb-0.1.0~458 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a092c1d38bac59ba04789306b58a892538ee2e08;p=sysdb.git utils unixsock: Added wrappers for clearerr(), feof(), and ferror(). --- diff --git a/src/include/utils/unixsock.h b/src/include/utils/unixsock.h index 0df0b71..d406613 100644 --- a/src/include/utils/unixsock.h +++ b/src/include/utils/unixsock.h @@ -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); diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index af1f2fe..11ddd7d 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -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) {