summaryrefslogtreecommitdiff
path: root/src/util/bio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/bio.c')
-rw-r--r--src/util/bio.c378
1 files changed, 190 insertions, 188 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index 5cbeee084..e05258f73 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -25,7 +25,7 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27 27
28#define LOG(kind, ...) GNUNET_log_from(kind, "util-bio", __VA_ARGS__) 28#define LOG(kind, ...) GNUNET_log_from (kind, "util-bio", __VA_ARGS__)
29 29
30#ifndef PATH_MAX 30#ifndef PATH_MAX
31/** 31/**
@@ -50,7 +50,8 @@
50/** 50/**
51 * Handle for buffered reading. 51 * Handle for buffered reading.
52 */ 52 */
53struct GNUNET_BIO_ReadHandle { 53struct GNUNET_BIO_ReadHandle
54{
54 /** 55 /**
55 * Underlying file abstraction. 56 * Underlying file abstraction.
56 */ 57 */
@@ -90,16 +91,16 @@ struct GNUNET_BIO_ReadHandle {
90 * @return IO handle on success, NULL on error 91 * @return IO handle on success, NULL on error
91 */ 92 */
92struct GNUNET_BIO_ReadHandle * 93struct GNUNET_BIO_ReadHandle *
93GNUNET_BIO_read_open(const char *fn) 94GNUNET_BIO_read_open (const char *fn)
94{ 95{
95 struct GNUNET_DISK_FileHandle *fd; 96 struct GNUNET_DISK_FileHandle *fd;
96 struct GNUNET_BIO_ReadHandle *h; 97 struct GNUNET_BIO_ReadHandle *h;
97 98
98 fd = GNUNET_DISK_file_open(fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 99 fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
99 if (NULL == fd) 100 if (NULL == fd)
100 return NULL; 101 return NULL;
101 h = GNUNET_malloc(sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); 102 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
102 h->buffer = (char *)&h[1]; 103 h->buffer = (char *) &h[1];
103 h->size = BIO_BUFFER_SIZE; 104 h->size = BIO_BUFFER_SIZE;
104 h->fd = fd; 105 h->fd = fd;
105 return h; 106 return h;
@@ -115,7 +116,7 @@ GNUNET_BIO_read_open(const char *fn)
115 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 116 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
116 */ 117 */
117int 118int
118GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg) 119GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
119{ 120{
120 int err; 121 int err;
121 122
@@ -123,9 +124,9 @@ GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
123 if (emsg != NULL) 124 if (emsg != NULL)
124 *emsg = h->emsg; 125 *emsg = h->emsg;
125 else 126 else
126 GNUNET_free_non_null(h->emsg); 127 GNUNET_free_non_null (h->emsg);
127 GNUNET_DISK_file_close(h->fd); 128 GNUNET_DISK_file_close (h->fd);
128 GNUNET_free(h); 129 GNUNET_free (h);
129 return err; 130 return err;
130} 131}
131 132
@@ -140,10 +141,10 @@ GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
140 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 141 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
141 */ 142 */
142int 143int
143GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, 144GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
144 const char *what, 145 const char *what,
145 void *result, 146 void *result,
146 size_t len) 147 size_t len)
147{ 148{
148 char *dst = result; 149 char *dst = result;
149 size_t min; 150 size_t min;
@@ -154,41 +155,41 @@ GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h,
154 return GNUNET_SYSERR; 155 return GNUNET_SYSERR;
155 pos = 0; 156 pos = 0;
156 do 157 do
158 {
159 /* first, use buffer */
160 min = h->have - h->pos;
161 if (min > 0)
157 { 162 {
158 /* first, use buffer */ 163 if (min > len - pos)
159 min = h->have - h->pos; 164 min = len - pos;
160 if (min > 0) 165 GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
161 { 166 h->pos += min;
162 if (min > len - pos) 167 pos += min;
163 min = len - pos;
164 GNUNET_memcpy(&dst[pos], &h->buffer[h->pos], min);
165 h->pos += min;
166 pos += min;
167 }
168 if (pos == len)
169 return GNUNET_OK; /* done! */
170 GNUNET_assert(((off_t)h->have) == h->pos);
171 /* fill buffer */
172 ret = GNUNET_DISK_file_read(h->fd, h->buffer, h->size);
173 if (-1 == ret)
174 {
175 GNUNET_asprintf(&h->emsg,
176 _("Error reading `%s': %s"),
177 what,
178 strerror(errno));
179 return GNUNET_SYSERR;
180 }
181 if (0 == ret)
182 {
183 GNUNET_asprintf(&h->emsg,
184 _("Error reading `%s': %s"),
185 what,
186 _("End of file"));
187 return GNUNET_SYSERR;
188 }
189 h->pos = 0;
190 h->have = ret;
191 } 168 }
169 if (pos == len)
170 return GNUNET_OK; /* done! */
171 GNUNET_assert (((off_t) h->have) == h->pos);
172 /* fill buffer */
173 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
174 if (-1 == ret)
175 {
176 GNUNET_asprintf (&h->emsg,
177 _ ("Error reading `%s': %s"),
178 what,
179 strerror (errno));
180 return GNUNET_SYSERR;
181 }
182 if (0 == ret)
183 {
184 GNUNET_asprintf (&h->emsg,
185 _ ("Error reading `%s': %s"),
186 what,
187 _ ("End of file"));
188 return GNUNET_SYSERR;
189 }
190 h->pos = 0;
191 h->have = ret;
192 }
192 while (pos < len); /* should always be true */ 193 while (pos < len); /* should always be true */
193 return GNUNET_OK; 194 return GNUNET_OK;
194} 195}
@@ -205,16 +206,16 @@ GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h,
205 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 206 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
206 */ 207 */
207int 208int
208GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h, 209GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
209 const char *file, 210 const char *file,
210 int line, 211 int line,
211 void *result, 212 void *result,
212 size_t len) 213 size_t len)
213{ 214{
214 char what[PATH_MAX + 1024]; 215 char what[PATH_MAX + 1024];
215 216
216 GNUNET_snprintf(what, sizeof(what), "%s:%d", file, line); 217 GNUNET_snprintf (what, sizeof(what), "%s:%d", file, line);
217 return GNUNET_BIO_read(h, what, result, len); 218 return GNUNET_BIO_read (h, what, result, len);
218} 219}
219 220
220 221
@@ -229,45 +230,45 @@ GNUNET_BIO_read_fn(struct GNUNET_BIO_ReadHandle *h,
229 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 230 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
230 */ 231 */
231int 232int
232GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, 233GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
233 const char *what, 234 const char *what,
234 char **result, 235 char **result,
235 size_t max_length) 236 size_t max_length)
236{ 237{
237 char *buf; 238 char *buf;
238 uint32_t big; 239 uint32_t big;
239 240
240 if (GNUNET_OK != GNUNET_BIO_read_int32(h, &big)) 241 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
241 { 242 {
242 GNUNET_free_non_null(h->emsg); 243 GNUNET_free_non_null (h->emsg);
243 GNUNET_asprintf(&h->emsg, _("Error reading length of string `%s'"), what); 244 GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
244 return GNUNET_SYSERR; 245 return GNUNET_SYSERR;
245 } 246 }
246 if (0 == big) 247 if (0 == big)
247 { 248 {
248 *result = NULL; 249 *result = NULL;
249 return GNUNET_OK; 250 return GNUNET_OK;
250 } 251 }
251 if (big > max_length) 252 if (big > max_length)
252 { 253 {
253 GNUNET_asprintf(&h->emsg, 254 GNUNET_asprintf (&h->emsg,
254 _("String `%s' longer than allowed (%u > %u)"), 255 _ ("String `%s' longer than allowed (%u > %u)"),
255 what, 256 what,
256 big, 257 big,
257 max_length); 258 max_length);
258 return GNUNET_SYSERR; 259 return GNUNET_SYSERR;
259 } 260 }
260 buf = GNUNET_malloc(big); 261 buf = GNUNET_malloc (big);
261 *result = buf; 262 *result = buf;
262 buf[--big] = '\0'; 263 buf[--big] = '\0';
263 if (0 == big) 264 if (0 == big)
264 return GNUNET_OK; 265 return GNUNET_OK;
265 if (GNUNET_OK != GNUNET_BIO_read(h, what, buf, big)) 266 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
266 { 267 {
267 GNUNET_free(buf); 268 GNUNET_free (buf);
268 *result = NULL; 269 *result = NULL;
269 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
270 } 271 }
271 return GNUNET_OK; 272 return GNUNET_OK;
272} 273}
273 274
@@ -281,44 +282,44 @@ GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h,
281 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 282 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
282 */ 283 */
283int 284int
284GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h, 285GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
285 const char *what, 286 const char *what,
286 struct GNUNET_CONTAINER_MetaData **result) 287 struct GNUNET_CONTAINER_MetaData **result)
287{ 288{
288 uint32_t size; 289 uint32_t size;
289 char *buf; 290 char *buf;
290 struct GNUNET_CONTAINER_MetaData *meta; 291 struct GNUNET_CONTAINER_MetaData *meta;
291 292
292 if (GNUNET_OK != GNUNET_BIO_read_int32(h, (int32_t *)&size)) 293 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
293 return GNUNET_SYSERR; 294 return GNUNET_SYSERR;
294 if (size == 0) 295 if (size == 0)
295 { 296 {
296 *result = NULL; 297 *result = NULL;
297 return GNUNET_OK; 298 return GNUNET_OK;
298 } 299 }
299 if (size > MAX_META_DATA) 300 if (size > MAX_META_DATA)
300 { 301 {
301 GNUNET_asprintf(&h->emsg, 302 GNUNET_asprintf (&h->emsg,
302 _("Serialized metadata `%s' larger than allowed (%u>%u)"), 303 _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
303 what, 304 what,
304 size, 305 size,
305 MAX_META_DATA); 306 MAX_META_DATA);
306 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
307 } 308 }
308 buf = GNUNET_malloc(size); 309 buf = GNUNET_malloc (size);
309 if (GNUNET_OK != GNUNET_BIO_read(h, what, buf, size)) 310 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
310 { 311 {
311 GNUNET_free(buf); 312 GNUNET_free (buf);
312 return GNUNET_SYSERR; 313 return GNUNET_SYSERR;
313 } 314 }
314 meta = GNUNET_CONTAINER_meta_data_deserialize(buf, size); 315 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
315 if (NULL == meta) 316 if (NULL == meta)
316 { 317 {
317 GNUNET_free(buf); 318 GNUNET_free (buf);
318 GNUNET_asprintf(&h->emsg, _("Metadata `%s' failed to deserialize"), what); 319 GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what);
319 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
320 } 321 }
321 GNUNET_free(buf); 322 GNUNET_free (buf);
322 *result = meta; 323 *result = meta;
323 return GNUNET_OK; 324 return GNUNET_OK;
324} 325}
@@ -334,16 +335,16 @@ GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h,
334 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 335 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
335 */ 336 */
336int 337int
337GNUNET_BIO_read_int32__(struct GNUNET_BIO_ReadHandle *h, 338GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
338 const char *file, 339 const char *file,
339 int line, 340 int line,
340 int32_t *i) 341 int32_t *i)
341{ 342{
342 int32_t big; 343 int32_t big;
343 344
344 if (GNUNET_OK != GNUNET_BIO_read_fn(h, file, line, &big, sizeof(int32_t))) 345 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int32_t)))
345 return GNUNET_SYSERR; 346 return GNUNET_SYSERR;
346 *i = ntohl(big); 347 *i = ntohl (big);
347 return GNUNET_OK; 348 return GNUNET_OK;
348} 349}
349 350
@@ -358,16 +359,16 @@ GNUNET_BIO_read_int32__(struct GNUNET_BIO_ReadHandle *h,
358 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 359 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
359 */ 360 */
360int 361int
361GNUNET_BIO_read_int64__(struct GNUNET_BIO_ReadHandle *h, 362GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
362 const char *file, 363 const char *file,
363 int line, 364 int line,
364 int64_t *i) 365 int64_t *i)
365{ 366{
366 int64_t big; 367 int64_t big;
367 368
368 if (GNUNET_OK != GNUNET_BIO_read_fn(h, file, line, &big, sizeof(int64_t))) 369 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int64_t)))
369 return GNUNET_SYSERR; 370 return GNUNET_SYSERR;
370 *i = GNUNET_ntohll(big); 371 *i = GNUNET_ntohll (big);
371 return GNUNET_OK; 372 return GNUNET_OK;
372} 373}
373 374
@@ -375,7 +376,8 @@ GNUNET_BIO_read_int64__(struct GNUNET_BIO_ReadHandle *h,
375/** 376/**
376 * Handle for buffered writing. 377 * Handle for buffered writing.
377 */ 378 */
378struct GNUNET_BIO_WriteHandle { 379struct GNUNET_BIO_WriteHandle
380{
379 /** 381 /**
380 * Underlying file handle. 382 * Underlying file handle.
381 */ 383 */
@@ -405,21 +407,21 @@ struct GNUNET_BIO_WriteHandle {
405 * @return IO handle on success, NULL on error 407 * @return IO handle on success, NULL on error
406 */ 408 */
407struct GNUNET_BIO_WriteHandle * 409struct GNUNET_BIO_WriteHandle *
408GNUNET_BIO_write_open(const char *fn) 410GNUNET_BIO_write_open (const char *fn)
409{ 411{
410 struct GNUNET_DISK_FileHandle *fd; 412 struct GNUNET_DISK_FileHandle *fd;
411 struct GNUNET_BIO_WriteHandle *h; 413 struct GNUNET_BIO_WriteHandle *h;
412 414
413 fd = 415 fd =
414 GNUNET_DISK_file_open(fn, 416 GNUNET_DISK_file_open (fn,
415 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | 417 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
416 GNUNET_DISK_OPEN_CREATE, 418 | GNUNET_DISK_OPEN_CREATE,
417 GNUNET_DISK_PERM_USER_READ | 419 GNUNET_DISK_PERM_USER_READ
418 GNUNET_DISK_PERM_USER_WRITE); 420 | GNUNET_DISK_PERM_USER_WRITE);
419 if (NULL == fd) 421 if (NULL == fd)
420 return NULL; 422 return NULL;
421 h = GNUNET_malloc(sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); 423 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
422 h->buffer = (char *)&h[1]; 424 h->buffer = (char *) &h[1];
423 h->size = BIO_BUFFER_SIZE; 425 h->size = BIO_BUFFER_SIZE;
424 h->fd = fd; 426 h->fd = fd;
425 return h; 427 return h;
@@ -433,14 +435,14 @@ GNUNET_BIO_write_open(const char *fn)
433 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 435 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
434 */ 436 */
435int 437int
436GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h) 438GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
437{ 439{
438 int ret; 440 int ret;
439 441
440 ret = GNUNET_SYSERR; 442 ret = GNUNET_SYSERR;
441 if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush(h)))) 443 if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))))
442 GNUNET_DISK_file_close(h->fd); 444 GNUNET_DISK_file_close (h->fd);
443 GNUNET_free(h); 445 GNUNET_free (h);
444 return ret; 446 return ret;
445} 447}
446 448
@@ -453,17 +455,17 @@ GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
453 * the file is closed 455 * the file is closed
454 */ 456 */
455int 457int
456GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h) 458GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
457{ 459{
458 ssize_t ret; 460 ssize_t ret;
459 461
460 ret = GNUNET_DISK_file_write(h->fd, h->buffer, h->have); 462 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
461 if (ret != (ssize_t)h->have) 463 if (ret != (ssize_t) h->have)
462 { 464 {
463 GNUNET_DISK_file_close(h->fd); 465 GNUNET_DISK_file_close (h->fd);
464 h->fd = NULL; 466 h->fd = NULL;
465 return GNUNET_SYSERR; /* error */ 467 return GNUNET_SYSERR; /* error */
466 } 468 }
467 h->have = 0; 469 h->have = 0;
468 return GNUNET_OK; 470 return GNUNET_OK;
469} 471}
@@ -478,9 +480,9 @@ GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
478 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 480 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
479 */ 481 */
480int 482int
481GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, 483GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
482 const void *buffer, 484 const void *buffer,
483 size_t n) 485 size_t n)
484{ 486{
485 const char *src = buffer; 487 const char *src = buffer;
486 size_t min; 488 size_t min;
@@ -490,22 +492,22 @@ GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h,
490 return GNUNET_SYSERR; 492 return GNUNET_SYSERR;
491 pos = 0; 493 pos = 0;
492 do 494 do
493 { 495 {
494 /* first, just use buffer */ 496 /* first, just use buffer */
495 min = h->size - h->have; 497 min = h->size - h->have;
496 if (min > n - pos) 498 if (min > n - pos)
497 min = n - pos; 499 min = n - pos;
498 GNUNET_memcpy(&h->buffer[h->have], &src[pos], min); 500 GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
499 pos += min; 501 pos += min;
500 h->have += min; 502 h->have += min;
501 if (pos == n) 503 if (pos == n)
502 return GNUNET_OK; /* done */ 504 return GNUNET_OK; /* done */
503 GNUNET_assert(h->have == h->size); 505 GNUNET_assert (h->have == h->size);
504 if (GNUNET_OK != GNUNET_BIO_flush(h)) 506 if (GNUNET_OK != GNUNET_BIO_flush (h))
505 return GNUNET_SYSERR; /* error */ 507 return GNUNET_SYSERR; /* error */
506 } 508 }
507 while (pos < n); /* should always be true */ 509 while (pos < n); /* should always be true */
508 GNUNET_break(0); 510 GNUNET_break (0);
509 return GNUNET_OK; 511 return GNUNET_OK;
510} 512}
511 513
@@ -518,15 +520,15 @@ GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h,
518 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 520 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
519 */ 521 */
520int 522int
521GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s) 523GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
522{ 524{
523 uint32_t slen; 525 uint32_t slen;
524 526
525 slen = (uint32_t)((s == NULL) ? 0 : strlen(s) + 1); 527 slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
526 if (GNUNET_OK != GNUNET_BIO_write_int32(h, slen)) 528 if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen))
527 return GNUNET_SYSERR; 529 return GNUNET_SYSERR;
528 if (0 != slen) 530 if (0 != slen)
529 return GNUNET_BIO_write(h, s, slen - 1); 531 return GNUNET_BIO_write (h, s, slen - 1);
530 return GNUNET_OK; 532 return GNUNET_OK;
531} 533}
532 534
@@ -539,32 +541,32 @@ GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *s)
539 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 541 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
540 */ 542 */
541int 543int
542GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, 544GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
543 const struct GNUNET_CONTAINER_MetaData *m) 545 const struct GNUNET_CONTAINER_MetaData *m)
544{ 546{
545 ssize_t size; 547 ssize_t size;
546 char *buf; 548 char *buf;
547 549
548 if (m == NULL) 550 if (m == NULL)
549 return GNUNET_BIO_write_int32(h, 0); 551 return GNUNET_BIO_write_int32 (h, 0);
550 buf = NULL; 552 buf = NULL;
551 size = GNUNET_CONTAINER_meta_data_serialize( 553 size = GNUNET_CONTAINER_meta_data_serialize (
552 m, 554 m,
553 &buf, 555 &buf,
554 MAX_META_DATA, 556 MAX_META_DATA,
555 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); 557 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
556 if (size == -1) 558 if (size == -1)
557 { 559 {
558 GNUNET_free(buf); 560 GNUNET_free (buf);
559 return GNUNET_SYSERR; 561 return GNUNET_SYSERR;
560 } 562 }
561 if ((GNUNET_OK != GNUNET_BIO_write_int32(h, (uint32_t)size)) || 563 if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) ||
562 (GNUNET_OK != GNUNET_BIO_write(h, buf, size))) 564 (GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
563 { 565 {
564 GNUNET_free(buf); 566 GNUNET_free (buf);
565 return GNUNET_SYSERR; 567 return GNUNET_SYSERR;
566 } 568 }
567 GNUNET_free(buf); 569 GNUNET_free (buf);
568 return GNUNET_OK; 570 return GNUNET_OK;
569} 571}
570 572
@@ -577,12 +579,12 @@ GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h,
577 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 579 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
578 */ 580 */
579int 581int
580GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i) 582GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
581{ 583{
582 int32_t big; 584 int32_t big;
583 585
584 big = htonl(i); 586 big = htonl (i);
585 return GNUNET_BIO_write(h, &big, sizeof(int32_t)); 587 return GNUNET_BIO_write (h, &big, sizeof(int32_t));
586} 588}
587 589
588 590
@@ -594,12 +596,12 @@ GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, int32_t i)
594 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 596 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
595 */ 597 */
596int 598int
597GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i) 599GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
598{ 600{
599 int64_t big; 601 int64_t big;
600 602
601 big = GNUNET_htonll(i); 603 big = GNUNET_htonll (i);
602 return GNUNET_BIO_write(h, &big, sizeof(int64_t)); 604 return GNUNET_BIO_write (h, &big, sizeof(int64_t));
603} 605}
604 606
605 607