[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26323 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26323 - in gnunet/src: include util |
Date: |
Tue, 5 Mar 2013 14:48:14 +0100 |
Author: grothoff
Date: 2013-03-05 14:48:14 +0100 (Tue, 05 Mar 2013)
New Revision: 26323
Modified:
gnunet/src/include/gnunet_strings_lib.h
gnunet/src/util/strings.c
Log:
-improve strings API
Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h 2013-03-05 13:40:12 UTC (rev
26322)
+++ gnunet/src/include/gnunet_strings_lib.h 2013-03-05 13:48:14 UTC (rev
26323)
@@ -279,7 +279,7 @@
* @return pointer to the next byte in 'out' or NULL on error.
*/
char *
-GNUNET_STRINGS_data_to_string (const unsigned char *data,
+GNUNET_STRINGS_data_to_string (const void *data,
size_t size,
char *out,
size_t out_size);
@@ -292,13 +292,13 @@
* @param enc the encoding
* @param enclen number of characters in 'enc' (without 0-terminator, which
can be missing)
* @param out location where to store the decoded data
- * @param out_size sizeof the output buffer
+ * @param out_size size of the output buffer
* @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
*/
int
GNUNET_STRINGS_string_to_data (const char *enc,
size_t enclen,
- unsigned char *out,
+ void *out,
size_t out_size);
Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c 2013-03-05 13:40:12 UTC (rev 26322)
+++ gnunet/src/util/strings.c 2013-03-05 13:48:14 UTC (rev 26323)
@@ -758,7 +758,7 @@
* @return pointer to the next byte in 'out' or NULL on error.
*/
char *
-GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, char
*out, size_t out_size)
+GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out,
size_t out_size)
{
/**
* 32 characters for encoding
@@ -768,9 +768,11 @@
unsigned int rpos;
unsigned int bits;
unsigned int vbit;
+ const unsigned char *udata;
GNUNET_assert (data != NULL);
GNUNET_assert (out != NULL);
+ udata = data;
if (out_size < (((size*8) + ((size*8) % 5)) % 5))
{
GNUNET_break (0);
@@ -784,7 +786,7 @@
{
if ((rpos < size) && (vbit < 5))
{
- bits = (bits << 8) | data[rpos++]; /* eat 8 more bits */
+ bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
vbit += 8;
}
if (vbit < 5)
@@ -823,7 +825,7 @@
*/
int
GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
- unsigned char *out, size_t out_size)
+ void *out, size_t out_size)
{
unsigned int rpos;
unsigned int wpos;
@@ -831,7 +833,10 @@
unsigned int vbit;
int ret;
int shift;
+ unsigned char *uout;
int encoded_len = out_size * 8;
+
+ uout = out;
if (encoded_len % 5 > 0)
{
vbit = encoded_len % 5; /* padding! */
@@ -859,13 +864,14 @@
vbit += 5;
if (vbit >= 8)
{
- out[--wpos] = (unsigned char) bits;
+ uout[--wpos] = (unsigned char) bits;
bits >>= 8;
vbit -= 8;
}
}
GNUNET_assert (rpos == 0);
GNUNET_assert (vbit == 0);
+
return GNUNET_OK;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26323 - in gnunet/src: include util,
gnunet <=