Kill duplicate para_fread()
authorAndre <maan@p133.(none)>
Sat, 13 May 2006 19:55:51 +0000 (21:55 +0200)
committerAndre <maan@p133.(none)>
Sat, 13 May 2006 19:55:51 +0000 (21:55 +0200)
This was contained in aac_afh.c as well as in mp3.c. Move it
to fd.c and add documentation.

aac_afh.c
fd.c
fd.h
mp3.c

index b091db03df14212bdb3d91a36c737b24170cd64f..d4a1866aeda37132531153c84c17d2f92a5b0f51 100644 (file)
--- 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 c5a37cdd2a4e5c28437df2fbbf3b44b313ac0636..ef2c64caced7aaef2751d6fa0233e0b33346dfae 100644 (file)
--- 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 66d3799fae2235ac1bfc41709aeb66a45fba8f96..e17f11f6b1e6bf3f7587c7914e6b0fd8a88c0ae1 100644 (file)
--- 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 ab05d2e7d62989e61305700cbccf997d2b3641ff..bc253aa5aeaa7a787550f9619d55d2c263ce25c7 100644 (file)
--- 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)