aboutsummaryrefslogtreecommitdiff
path: root/src/util/bio.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-13 19:46:45 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-13 19:46:45 +0000
commite5ba359af49fac05185f5ec0b4dbb47c7060167a (patch)
treec8146873eb3676714f2c370c067f5b7164146918 /src/util/bio.c
parentae202e69cb8d882992cac472a2fd86da0d0b18bf (diff)
downloadgnunet-e5ba359af49fac05185f5ec0b4dbb47c7060167a.tar.gz
gnunet-e5ba359af49fac05185f5ec0b4dbb47c7060167a.zip
-fixing resuming publish operation
Diffstat (limited to 'src/util/bio.c')
-rw-r--r--src/util/bio.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index dd2a182b1..b4f33f589 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -75,7 +75,7 @@ GNUNET_BIO_read_open (const char *fn)
75 * 75 *
76 * @param h file handle 76 * @param h file handle
77 * @param emsg set to the error message 77 * @param emsg set to the error message
78 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 78 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
79 */ 79 */
80int 80int
81GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) 81GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
@@ -100,7 +100,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
100 * @param what describes what is being read (for error message creation) 100 * @param what describes what is being read (for error message creation)
101 * @param result the buffer to write the result to 101 * @param result the buffer to write the result to
102 * @param len the number of bytes to read 102 * @param len the number of bytes to read
103 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 103 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
104 */ 104 */
105int 105int
106GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, 106GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
@@ -111,7 +111,7 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
111 size_t pos; 111 size_t pos;
112 ssize_t ret; 112 ssize_t ret;
113 113
114 if (h->emsg != NULL) 114 if (NULL != h->emsg)
115 return GNUNET_SYSERR; 115 return GNUNET_SYSERR;
116 pos = 0; 116 pos = 0;
117 do 117 do
@@ -131,15 +131,19 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
131 GNUNET_assert (h->have == h->pos); 131 GNUNET_assert (h->have == h->pos);
132 /* fill buffer */ 132 /* fill buffer */
133 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); 133 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
134 if (ret == -1) 134 if (-1 == ret)
135 { 135 {
136 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, 136 GNUNET_asprintf (&h->emsg,
137 _("Error reading `%s': %s"),
138 what,
137 STRERROR (errno)); 139 STRERROR (errno));
138 return GNUNET_SYSERR; 140 return GNUNET_SYSERR;
139 } 141 }
140 if (ret == 0) 142 if (0 == ret)
141 { 143 {
142 GNUNET_asprintf (&h->emsg, _("Error reading `%s': %s"), what, 144 GNUNET_asprintf (&h->emsg,
145 _("Error reading `%s': %s"),
146 what,
143 _("End of file")); 147 _("End of file"));
144 return GNUNET_SYSERR; 148 return GNUNET_SYSERR;
145 } 149 }
@@ -159,7 +163,7 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
159 * @param line line number in the source file 163 * @param line line number in the source file
160 * @param result the buffer to write the result to 164 * @param result the buffer to write the result to
161 * @param len the number of bytes to read 165 * @param len the number of bytes to read
162 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 166 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
163 */ 167 */
164int 168int
165GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, 169GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line,
@@ -180,7 +184,7 @@ GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line,
180 * @param result the buffer to store a pointer to the (allocated) string to 184 * @param result the buffer to store a pointer to the (allocated) string to
181 * (note that *result could be set to NULL as well) 185 * (note that *result could be set to NULL as well)
182 * @param maxLen maximum allowed length for the string 186 * @param maxLen maximum allowed length for the string
183 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 187 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
184 */ 188 */
185int 189int
186GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, 190GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
@@ -195,7 +199,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
195 GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what); 199 GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what);
196 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
197 } 201 }
198 if (big == 0) 202 if (0 == big)
199 { 203 {
200 *result = NULL; 204 *result = NULL;
201 return GNUNET_OK; 205 return GNUNET_OK;
@@ -209,7 +213,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
209 buf = GNUNET_malloc (big); 213 buf = GNUNET_malloc (big);
210 *result = buf; 214 *result = buf;
211 buf[--big] = '\0'; 215 buf[--big] = '\0';
212 if (big == 0) 216 if (0 == big)
213 return GNUNET_OK; 217 return GNUNET_OK;
214 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) 218 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
215 { 219 {
@@ -227,7 +231,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what,
227 * @param h handle to an open file 231 * @param h handle to an open file
228 * @param what describes what is being read (for error message creation) 232 * @param what describes what is being read (for error message creation)
229 * @param result the buffer to store a pointer to the (allocated) metadata 233 * @param result the buffer to store a pointer to the (allocated) metadata
230 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 234 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
231 */ 235 */
232int 236int
233GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, 237GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
@@ -277,7 +281,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what,
277 * @param file name of the source file 281 * @param file name of the source file
278 * @param line line number in the source file 282 * @param line line number in the source file
279 * @param i address of 32-bit integer to read 283 * @param i address of 32-bit integer to read
280 * @return GNUNET_OK on success, GNUNET_SYSERR on error 284 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 */ 285 */
282int 286int
283GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 287GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
@@ -299,7 +303,7 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
299 * @param file name of the source file 303 * @param file name of the source file
300 * @param line line number in the source file 304 * @param line line number in the source file
301 * @param i address of 64-bit integer to read 305 * @param i address of 64-bit integer to read
302 * @return GNUNET_OK on success, GNUNET_SYSERR on error 306 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
303 */ 307 */
304int 308int
305GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 309GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
@@ -357,7 +361,7 @@ GNUNET_BIO_write_open (const char *fn)
357 * Close an open file for writing. 361 * Close an open file for writing.
358 * 362 *
359 * @param h file handle 363 * @param h file handle
360 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 364 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
361 */ 365 */
362int 366int
363GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) 367GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
@@ -376,7 +380,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
376 * Force a buffered writer to flush its buffer 380 * Force a buffered writer to flush its buffer
377 * 381 *
378 * @param h the writer handle 382 * @param h the writer handle
379 * @return GNUNET_OK upon success. Upon failure GNUNET_SYSERR is returned and 383 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned and
380 * the file is closed 384 * the file is closed
381 */ 385 */
382int 386int
@@ -402,7 +406,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
402 * @param h handle to open file 406 * @param h handle to open file
403 * @param buffer the data to write 407 * @param buffer the data to write
404 * @param n number of bytes to write 408 * @param n number of bytes to write
405 * @return GNUNET_OK on success, GNUNET_SYSERR on error 409 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
406 */ 410 */
407int 411int
408GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, 412GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
@@ -441,10 +445,11 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
441 * 445 *
442 * @param h handle to open file 446 * @param h handle to open file
443 * @param s string to write (can be NULL) 447 * @param s string to write (can be NULL)
444 * @return GNUNET_OK on success, GNUNET_SYSERR on error 448 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
445 */ 449 */
446int 450int
447GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s) 451GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
452 const char *s)
448{ 453{
449 uint32_t slen; 454 uint32_t slen;
450 455
@@ -462,7 +467,7 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
462 * 467 *
463 * @param h handle to open file 468 * @param h handle to open file
464 * @param m metadata to write 469 * @param m metadata to write
465 * @return GNUNET_OK on success, GNUNET_SYSERR on error 470 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
466 */ 471 */
467int 472int
468GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, 473GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,