* @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 (h, __FILE__ "##__LINE__##", f, sizeof(float)))
* @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 (h, __FILE__ "##__LINE__##", f, sizeof(double)))
/**
* @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)
/**
* @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))
* @param h hande to open file
* @param f double to write (must be a variable)
*/
-#define GNUNET_BIO_write_double(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))
/**
char *buf;
uint32_t big;
- if (! GNUNET_BIO_read_int32 (h, &big))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
return GNUNET_SYSERR;
if (big == 0)
{
}
buf = GNUNET_malloc (big);
buf[--big] = '\0';
- if (big != GNUNET_BIO_read (h, what, buf, big))
+ if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
{
GNUNET_free (buf);
return GNUNET_SYSERR;
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (size);
- if (size !=
+ if (GNUNET_OK !=
GNUNET_BIO_read (h, what, buf, size))
{
GNUNET_free (buf);
{
int32_t big;
- if (sizeof (int32_t) !=
+ if (GNUNET_OK !=
GNUNET_BIO_read (h,
what,
&big,
{
int64_t big;
- if (sizeof (int64_t) !=
+ if (GNUNET_OK !=
GNUNET_BIO_read (h,
what,
&big,
*/
int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
{
+ ssize_t wrt;
int ret;
if (NULL == h->fd)
}
else
{
+ wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
+ if (wrt == h->have)
+ ret = GNUNET_OK;
+ else
+ ret = GNUNET_SYSERR;
GNUNET_DISK_file_close (h->fd);
- ret = GNUNET_OK;
}
GNUNET_free (h);
return ret;
main (int argc, char *argv[])
{
- char *readResultString;
+ char *readResultString;
int64_t testNumber = (int64_t)TESTNUMBER64;
-
- const char *writeString = TESTSTRING;
+ int64_t testNum;
char *msg;
char* fileName = GNUNET_DISK_mktemp ("gnunet_bio");
metaDataW = GNUNET_CONTAINER_meta_data_create();
GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW);
fileW = GNUNET_BIO_write_open(fileName);
- GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW,writeString));
+ GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW, TESTSTRING));
GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW));
GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber));
GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW));
fileR = GNUNET_BIO_read_open (fileName);
- GNUNET_BIO_read_meta_data(fileR,"Read meta error",&metaDataR);
- size_t readMaxLen = 200;
- //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR,"Read string error",&readResultString,readMaxLen));
- //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64__(fileR,"Read int64 error",&testNum));
- GNUNET_BIO_read_close(fileR,&msg);
+ GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error", &readResultString, 200));
+ GNUNET_BIO_read_meta_data(fileR, "Read meta error", &metaDataR);
+ GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64(fileR, &testNum));
+ GNUNET_BIO_read_close(fileR,&msg);
GNUNET_CONTAINER_meta_data_destroy(metaDataW);
GNUNET_CONTAINER_meta_data_destroy(metaDataR);
free(fileName);