aboutsummaryrefslogtreecommitdiff
path: root/src/util/bio.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-05 13:15:06 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-05 13:15:06 +0000
commitb93c5a4845284ddf08f57d6487a8950c36405bdc (patch)
tree403b071e3095f7b89ada8e219518da2146d661cf /src/util/bio.c
parentfcfef3ee8c14488a689636bab590d19b8ff3b43d (diff)
downloadgnunet-b93c5a4845284ddf08f57d6487a8950c36405bdc.tar.gz
gnunet-b93c5a4845284ddf08f57d6487a8950c36405bdc.zip
fix
Diffstat (limited to 'src/util/bio.c')
-rw-r--r--src/util/bio.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index b05746c38..ef31547be 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -147,6 +147,30 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
147 147
148 148
149/** 149/**
150 * Read the contents of a binary file into a buffer.
151 *
152 * @param h handle to an open file
153 * @param file name of the source file
154 * @param line line number in the source file
155 * @param result the buffer to write the result to
156 * @param len the number of bytes to read
157 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
158 */
159int GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
160 const char *file, int line,
161 void *result,
162 size_t len)
163{
164 char what[1024];
165 GNUNET_snprintf (what,
166 sizeof(what),
167 "%s:%d",
168 file, line);
169 return GNUNET_BIO_read (h, what, result, len);
170}
171
172
173/**
150 * Read 0-terminated string from a file. 174 * Read 0-terminated string from a file.
151 * 175 *
152 * @param h handle to an open file 176 * @param h handle to an open file
@@ -209,7 +233,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
209 char *buf; 233 char *buf;
210 struct GNUNET_CONTAINER_MetaData *meta; 234 struct GNUNET_CONTAINER_MetaData *meta;
211 235
212 if (GNUNET_BIO_read_int32__ (h, what, (int32_t *) &size) != GNUNET_OK) 236 if (GNUNET_BIO_read_int32 (h, (int32_t *) &size) != GNUNET_OK)
213 return GNUNET_SYSERR; 237 return GNUNET_SYSERR;
214 if (size > MAX_META_DATA) 238 if (size > MAX_META_DATA)
215 { 239 {
@@ -242,17 +266,20 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
242 * Read an (u)int32_t. 266 * Read an (u)int32_t.
243 * 267 *
244 * @param h hande to open file 268 * @param h hande to open file
245 * @param what describes what is being read (for error message creation) 269 * @param file name of the source file
270 * @param line line number in the source file
246 * @param i address of 32-bit integer to read 271 * @param i address of 32-bit integer to read
247 * @return GNUNET_OK on success, GNUNET_SYSERR on error 272 * @return GNUNET_OK on success, GNUNET_SYSERR on error
248 */ 273 */
249int 274int
250GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, 275GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
251 const char *what, int32_t * i) 276 const char *file,
277 int line,
278 int32_t * i)
252{ 279{
253 int32_t big; 280 int32_t big;
254 281
255 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int32_t))) 282 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t)))
256 return GNUNET_SYSERR; 283 return GNUNET_SYSERR;
257 *i = ntohl (big); 284 *i = ntohl (big);
258 return GNUNET_OK; 285 return GNUNET_OK;
@@ -263,17 +290,20 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
263 * Read an (u)int64_t. 290 * Read an (u)int64_t.
264 * 291 *
265 * @param h hande to open file 292 * @param h hande to open file
266 * @param what describes what is being read (for error message creation) 293 * @param file name of the source file
294 * @param line line number in the source file
267 * @param i address of 64-bit integer to read 295 * @param i address of 64-bit integer to read
268 * @return GNUNET_OK on success, GNUNET_SYSERR on error 296 * @return GNUNET_OK on success, GNUNET_SYSERR on error
269 */ 297 */
270int 298int
271GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, 299GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
272 const char *what, int64_t * i) 300 const char *file,
301 int line,
302 int64_t * i)
273{ 303{
274 int64_t big; 304 int64_t big;
275 305
276 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int64_t))) 306 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t)))
277 return GNUNET_SYSERR; 307 return GNUNET_SYSERR;
278 *i = GNUNET_ntohll (big); 308 *i = GNUNET_ntohll (big);
279 return GNUNET_OK; 309 return GNUNET_OK;