aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-01 16:08:38 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-01 16:08:38 +0200
commit2bb07d251cc8eead7a0fcf1c0c7100477f107027 (patch)
tree7a5416b77e8a8a69e18a3be524fe078cd381c1b0 /src/util
parent754d8c1b496624e5c879af7d142fc9fd34de3a21 (diff)
parent54b5a20700a1ed27b1067a7cd55329ddc5b0d611 (diff)
downloadgnunet-2bb07d251cc8eead7a0fcf1c0c7100477f107027.tar.gz
gnunet-2bb07d251cc8eead7a0fcf1c0c7100477f107027.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/util')
-rw-r--r--src/util/buffer.c32
-rw-r--r--src/util/disk.c14
2 files changed, 38 insertions, 8 deletions
diff --git a/src/util/buffer.c b/src/util/buffer.c
index d0261889e..8fb10c2a5 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -248,3 +248,35 @@ GNUNET_buffer_write_vfstr (struct GNUNET_Buffer *buf,
248 buf->position += res; 248 buf->position += res;
249 GNUNET_assert (buf->position <= buf->capacity); 249 GNUNET_assert (buf->position <= buf->capacity);
250} 250}
251
252
253/**
254 * Write data encoded via #GNUNET_STRINGS_data_to_string to the buffer.
255 *
256 * Grows the buffer if necessary.
257 *
258 * @param buf buffer to write to
259 * @param data data to read from
260 * @param len number of bytes to copy from @a data to @a buf
261 */
262void
263GNUNET_buffer_write_data_encoded (struct GNUNET_Buffer *buf,
264 const char *data,
265 size_t len)
266{
267 size_t outlen = len * 8;
268
269 if (outlen % 5 > 0)
270 outlen += 5 - outlen % 5;
271 outlen /= 5;
272
273 GNUNET_buffer_ensure_remaining (buf, outlen);
274 GNUNET_assert (NULL !=
275 GNUNET_STRINGS_data_to_string (data,
276 len,
277 (buf->mem +
278 buf->position),
279 outlen));
280 buf->position += outlen;
281 GNUNET_assert (buf->position <= buf->capacity);
282}
diff --git a/src/util/disk.c b/src/util/disk.c
index 6560726ea..c95e9753c 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1377,14 +1377,13 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1377 enum GNUNET_DISK_MapType access, 1377 enum GNUNET_DISK_MapType access,
1378 size_t len) 1378 size_t len)
1379{ 1379{
1380 int prot;
1381
1380 if (NULL == h) 1382 if (NULL == h)
1381 { 1383 {
1382 errno = EINVAL; 1384 errno = EINVAL;
1383 return NULL; 1385 return NULL;
1384 } 1386 }
1385
1386 int prot;
1387
1388 prot = 0; 1387 prot = 0;
1389 if (access & GNUNET_DISK_MAP_TYPE_READ) 1388 if (access & GNUNET_DISK_MAP_TYPE_READ)
1390 prot = PROT_READ; 1389 prot = PROT_READ;
@@ -1405,22 +1404,21 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1405 1404
1406/** 1405/**
1407 * Unmap a file 1406 * Unmap a file
1407 *
1408 * @param h mapping handle 1408 * @param h mapping handle
1409 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 1409 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1410 */ 1410 */
1411int 1411int
1412GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) 1412GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
1413{ 1413{
1414 int ret; 1414 int ret;
1415 1415
1416 if (h == NULL) 1416 if (NULL == h)
1417 { 1417 {
1418 errno = EINVAL; 1418 errno = EINVAL;
1419 return GNUNET_SYSERR; 1419 return GNUNET_SYSERR;
1420 } 1420 }
1421
1422 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; 1421 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1423
1424 GNUNET_free (h); 1422 GNUNET_free (h);
1425 return ret; 1423 return ret;
1426} 1424}
@@ -1429,7 +1427,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
1429/** 1427/**
1430 * Write file changes to disk 1428 * Write file changes to disk
1431 * @param h handle to an open file 1429 * @param h handle to an open file
1432 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 1430 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1433 */ 1431 */
1434int 1432int
1435GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) 1433GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)