From: Andre Date: Sat, 13 May 2006 19:55:51 +0000 (+0200) Subject: Kill duplicate para_fread() X-Git-Tag: v0.2.14~124 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=6acf01b71c38441686d6167617feee86a2960d62 Kill duplicate para_fread() This was contained in aac_afh.c as well as in mp3.c. Move it to fd.c and add documentation. --- diff --git a/aac_afh.c b/aac_afh.c index b091db03..d4a1866a 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -28,6 +28,7 @@ #include "error.h" #include "string.h" #include "aac.h" +#include "fd.h" /* must be big enough to hold header */ #define DEFAULT_INBUF_SIZE 65536 @@ -197,16 +198,6 @@ static int aac_reposition_stream(long unsigned request) // return -E_AAC_REPOS; } -static __must_check int para_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t res = fread(ptr, size, nmemb, stream); - if (res == nmemb) - return size * nmemb; - if (feof(stream)) - return 0; - return -E_FREAD; -} - static char *aac_read_chunk(long unsigned current_chunk, ssize_t *len) { int ret; diff --git a/fd.c b/fd.c index c5a37cdd..ef2c64ca 100644 --- a/fd.c +++ b/fd.c @@ -94,9 +94,34 @@ int mark_fd_nonblock(int fd) * * This wrapper for FD_SET() passes its first two arguments to \p FD_SET. Upon * return, \a max_fileno contains the maximum of the old_value and \a fd. + * + * \sa para_select */ void para_fd_set(int fd, fd_set *fds, int *max_fileno) { FD_SET(fd, fds); *max_fileno = PARA_MAX(*max_fileno, fd); } + +/** + * paraslash's wrapper for fread(3) + * + * \param dest destination pointer + * \param nbytes size of one element + * \param nmemb number of elements to write + * \param stream the input stream + * + * \return negative on errors, zero on end of file, and the number of bytes + * (not elements) read on success. + * + * \sa fread(3) + */ +__must_check int para_fread(void *dest, size_t nbytes, size_t nmemb, FILE *stream) +{ + size_t res = fread(dest, nbytes, nmemb, stream); + if (res == nmemb) + return nbytes * nmemb; + if (feof(stream)) + return 0; + return -E_FREAD; +} diff --git a/fd.h b/fd.h index 66d3799f..e17f11f6 100644 --- a/fd.h +++ b/fd.h @@ -23,3 +23,4 @@ int para_select(int n, fd_set *readfds, fd_set *writefds, struct timeval *timeout); int mark_fd_nonblock(int fd); void para_fd_set(int fd, fd_set *fds, int *max_fileno); +__must_check int para_fread(void *dest, size_t nbytes, size_t nmemb, FILE *stream); diff --git a/mp3.c b/mp3.c index ab05d2e7..bc253aa5 100644 --- a/mp3.c +++ b/mp3.c @@ -32,6 +32,7 @@ #include "server.h" #include "afs.h" #include "error.h" +#include "fd.h" /** \cond some defines and structs which are only used in this file */ @@ -108,16 +109,6 @@ static char mp3buf[8192]; static int chunk_size; static struct audio_format *af; -static __must_check int para_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t res = fread(ptr, size, nmemb, stream); - if (res == nmemb) - return size * nmemb; - if (feof(stream)) - return 0; - return -E_FREAD; -} - static int header_frequency(struct mp3header *h) { if (h->version > 2 || h->freq > 3)