for w32 port
[oweals/gnunet.git] / src / include / gnunet_bio_lib.h
index 02b04570eabc226ca9df15be6dcca17ccbc962a6..15924f1efcc3e00ef072eec31c919ab8547ad707 100644 (file)
@@ -71,12 +71,28 @@ int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
  * @param what describes what is being read (for error message creation)
  * @param result the buffer to write the result to
  * @param len the number of bytes to read
- * @return len on success, GNUNET_SYSERR on failure
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  */
-ssize_t GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 
-                        const char *what,
-                        void *result, 
-                        size_t len);
+int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 
+                    const char *what,
+                    void *result, 
+                    size_t len);
+
+
+/**
+ * Read the contents of a binary file into a buffer.
+ *
+ * @param h handle to an open file
+ * @param file name of the source file
+ * @param line line number in the source file
+ * @param result the buffer to write the result to
+ * @param len the number of bytes to read
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, 
+                       const char *file, int line,
+                       void *result, 
+                       size_t len);
 
 /**
  * Read 0-terminated string from a file.
@@ -85,11 +101,13 @@ ssize_t GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
  * @param what describes what is being read (for error message creation)
  * @param result the buffer to store a pointer to the (allocated) string to
  *        (note that *result could be set to NULL as well)
+ * @param maxLen maximum allowed length for the string
  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  */
-int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 
+int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
                            const char *what,
-                           char **result);
+                           char **result,
+                           size_t maxLen);
 
 
 /**
@@ -111,7 +129,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param f address of float to read
  */ 
-#define GNUNET_BIO_read_float(h, f) (sizeof(float) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(float)))
+#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, f, sizeof(float)))
 
 
 
@@ -121,19 +139,20 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param f address of double to read
  */ 
-#define GNUNET_BIO_read_double(h, f) (sizeof(double) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(double)))
+#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, f, sizeof(double)))
 
 
 /**
  * Read an (u)int32_t.
  *
  * @param h hande to open file
- * @param what describes what is being read (for error message creation)
+ * @param file name of the source file
+ * @param line line number in the code
  * @param i address of 32-bit integer to read
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */ 
 int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, 
-                            const char *what,
+                            const char *file, int line,
                             int32_t *i);
 
 
@@ -143,19 +162,20 @@ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param i address of 32-bit integer to read
  */ 
-#define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__ "##__LINE__##", (int32_t*) i)
+#define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__, __LINE__, (int32_t*) i)
 
 
 /**
  * Read an (u)int64_t.
  *
  * @param h hande to open file
- * @param what describes what is being read (for error message creation)
+ * @param file name of the source file
+ * @param line line number in the code
  * @param i address of 64-bit integer to read
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */ 
 int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, 
-                            const char *what,
+                            const char *file, int line,
                             int64_t *i);
 
 
@@ -165,7 +185,7 @@ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param i address of 64-bit integer to read
  */ 
-#define GNUNET_BIO_read_int64(h, i) (sizeof(int64_t) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", (int64_t*) i, sizeof(int64_t)))
+#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__, __LINE__, (int64_t*) i)
 
 
 /**
@@ -198,9 +218,9 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h);
  * @param n number of bytes to write
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */
-ssize_t GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 
-                         const void *buffer,
-                         size_t n);
+int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 
+                     const void *buffer,
+                     size_t n);
 
 
 /**
@@ -234,7 +254,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
  * @param h hande to open file
  * @param f float to write (must be a variable)
  */ 
-#define GNUNET_BIO_write_float(h, f) (sizeof(float) == GNUNET_BIO_write (h, &f, sizeof(float)))
+#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float))
 
 
 
@@ -244,7 +264,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
  * @param h hande to open file
  * @param f double to write (must be a variable)
  */ 
-#define GNUNET_BIO_write_float(h, f) (sizeof(double) == GNUNET_BIO_write (h, &f, sizeof(double)))
+#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double))
 
 
 /**
@@ -254,7 +274,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
  * @param i address of 32-bit integer to write
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */ 
-int GNUNET_BIO_write_int32 (struct GNUNET_BIO_ReadHandle *h, 
+int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 
                            int32_t i);
 
 
@@ -265,7 +285,7 @@ int GNUNET_BIO_write_int32 (struct GNUNET_BIO_ReadHandle *h,
  * @param i address of 64-bit integer to write
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
  */ 
-int GNUNET_BIO_write_int64 (struct GNUNET_BIO_ReadHandle *h, 
+int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 
                            int64_t i);