* used to parse the buffer back into individual
* strings.
*
+ * @param buffer the buffer to fill with strings, can
+ * be NULL in which case only the necessary
+ * amount of space will be calculated
+ * @param size number of bytes available in buffer
+ * @param count number of strings that follow
+ * @param ... count 0-terminated strings to copy to buffer
* @return number of bytes written to the buffer
* (or number of bytes that would have been written)
*/
-unsigned int
+size_t
GNUNET_STRINGS_buffer_fill (char *buffer,
- unsigned int size, unsigned int count, ...)
+ size_t size, unsigned int count, ...)
{
- unsigned int needed;
- unsigned int slen;
+ size_t needed;
+ size_t slen;
const char *s;
va_list ap;
*/
unsigned int
GNUNET_STRINGS_buffer_tokenize (const char *buffer,
- unsigned int size, unsigned int count, ...)
+ size_t size, unsigned int count, ...)
{
unsigned int start;
unsigned int needed;
/**
* Convert a given filesize into a fancy human-readable format.
+ *
+ * @param size number of bytes
+ * @return fancy representation of the size (possibly rounded) for humans
*/
char *
GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
}
}
ret = GNUNET_malloc (32);
- GNUNET_snprintf (ret, 32, "%llu%s", size, unit);
+ GNUNET_snprintf (ret, 32, "%llu %s", size, unit);
return ret;
}
tmp = GNUNET_malloc (tmpSize);
itmp = tmp;
finSize = tmpSize;
- if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == (size_t) - 1)
+ if (iconv (cd,
+#if FREEBSD || DARWIN
+ (const char **) &input,
+#else
+ (char **) &input,
+#endif
+ &len, &itmp, &finSize) == (size_t) - 1)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv");
iconv_close (cd);
/**
* Give relative time in human-readable fancy format.
+ *
* @param delta time in milli seconds
+ * @return time as human-readable string
*/
char *
-GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative del)
+GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta)
{
const char *unit = _( /* time unit */ "ms");
char *ret;
- uint64_t delta = del.value;
+ uint64_t dval = delta.value;
- if (delta > 5 * 1000)
+ if (delta.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
+ return GNUNET_strdup (_("eternity"));
+ if (dval > 5 * 1000)
{
- delta = delta / 1000;
+ dval = dval / 1000;
unit = _( /* time unit */ "s");
- if (delta > 5 * 60)
+ if (dval > 5 * 60)
{
- delta = delta / 60;
+ dval = dval / 60;
unit = _( /* time unit */ "m");
- if (delta > 5 * 60)
+ if (dval > 5 * 60)
{
- delta = delta / 60;
+ dval = dval / 60;
unit = _( /* time unit */ "h");
- if (delta > 5 * 24)
+ if (dval > 5 * 24)
{
- delta = delta / 24;
+ dval = dval / 24;
unit = _( /* time unit */ " days");
}
}
}
}
- GNUNET_asprintf (&ret, "%llu%s", delta, unit);
+ GNUNET_asprintf (&ret, "%llu %s", dval, unit);
return ret;
}
/**
* "man ctime_r", except for GNUnet time; also, unlike ctime, the
* return value does not include the newline character.
+ *
+ * @param t time to convert
+ * @return absolute time in human-readable format
*/
char *
GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
time_t tt;
char *ret;
+ if (t.value == GNUNET_TIME_UNIT_FOREVER_ABS.value)
+ return GNUNET_strdup (_("end of time"));
tt = t.value / 1000;
#ifdef ctime_r
ret = ctime_r (&tt, GNUNET_malloc (32));