Update plibc header
[oweals/gnunet.git] / src / util / strings.c
index 3d061fb578db5b0803d1026d58099f44d64fffe1..cddb4bb07cbd814dcefb8bee52d17e94868b4162 100644 (file)
@@ -291,7 +291,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
  *
  * @param fancy_time human readable string (i.e. 1 minute)
  * @param rtime set to the relative time
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
 GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
@@ -332,11 +332,12 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
 
 /**
  * Convert a given fancy human-readable time to our internal
- * representation.
+ * representation. The human-readable time is expected to be
+ * in local time, whereas the returned value will be in UTC.
  *
  * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S)
  * @param atime set to the absolute time
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
 GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
@@ -375,14 +376,19 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
  * Convert the len characters long character sequence
  * given in input that is in the given input charset
  * to a string in given output charset.
+ *
+ * @param input input string
+ * @param len number of bytes in @a input
+ * @param input_charset character set used for @a input
+ * @param ouptut_charset desired character set for the return value
  * @return the converted string (0-terminated),
  *  if conversion fails, a copy of the orignal
  *  string is returned.
  */
 char *
 GNUNET_STRINGS_conv (const char *input,
-                    size_t len, 
-                    const char *input_charset, 
+                    size_t len,
+                    const char *input_charset,
                     const char *output_charset)
 {
   char *ret;
@@ -391,10 +397,10 @@ GNUNET_STRINGS_conv (const char *input,
   size_t u8_string_length;
   size_t encoded_string_length;
 
-  u8_string = u8_conv_from_encoding (input_charset, 
-                                    iconveh_error, 
-                                    input, len, 
-                                    NULL, NULL, 
+  u8_string = u8_conv_from_encoding (input_charset,
+                                    iconveh_error,
+                                    input, len,
+                                    NULL, NULL,
                                     &u8_string_length);
   if (NULL == u8_string)
   {
@@ -409,9 +415,9 @@ GNUNET_STRINGS_conv (const char *input,
     free (u8_string);
     return ret;
   }
-  encoded_string = u8_conv_to_encoding (output_charset, iconveh_error, 
-                                       u8_string, u8_string_length, 
-                                       NULL, NULL, 
+  encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
+                                       u8_string, u8_string_length,
+                                       NULL, NULL,
                                        &encoded_string_length);
   free (u8_string);
   if (NULL == encoded_string)
@@ -438,12 +444,18 @@ GNUNET_STRINGS_conv (const char *input,
  * Convert the len characters long character sequence
  * given in input that is in the given charset
  * to UTF-8.
+ *
+ * @param input the input string (not necessarily 0-terminated)
+ * @param len the number of bytes in the @a input
+ * @param charset character set to convert from
  * @return the converted string (0-terminated),
  *  if conversion fails, a copy of the orignal
  *  string is returned.
  */
 char *
-GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
+GNUNET_STRINGS_to_utf8 (const char *input,
+                        size_t len,
+                        const char *charset)
 {
   return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
 }
@@ -453,12 +465,17 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
  * Convert the len bytes-long UTF-8 string
  * given in input to the given charset.
  *
+ * @param input the input string (not necessarily 0-terminated)
+ * @param len the number of bytes in the @a input
+ * @param charset character set to convert to
  * @return the converted string (0-terminated),
  *  if conversion fails, a copy of the orignal
  *  string is returned.
  */
 char *
-GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
+GNUNET_STRINGS_from_utf8 (const char *input,
+                          size_t len,
+                          const char *charset)
 {
   return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
 }
@@ -644,14 +661,14 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
     return _("forever");
   if (0 == delta.rel_value_us)
     return _("0 ms");
-  if ( ( (GNUNET_YES == do_round) && 
-        (dval > 5 * 1000) ) || 
+  if ( ( (GNUNET_YES == do_round) &&
+        (dval > 5 * 1000) ) ||
        (0 == (dval % 1000) ))
   {
     dval = dval / 1000;
     unit = _( /* time unit */ "ms");
-    if ( ( (GNUNET_YES == do_round) && 
-          (dval > 5 * 1000) ) || 
+    if ( ( (GNUNET_YES == do_round) &&
+          (dval > 5 * 1000) ) ||
         (0 == (dval % 1000) ))
     {
       dval = dval / 1000;
@@ -663,7 +680,7 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
        dval = dval / 60;
        unit = _( /* time unit */ "m");
        if ( ( (GNUNET_YES == do_round) &&
-              (dval > 5 * 60) ) || 
+              (dval > 5 * 60) ) ||
             (0 == (dval % 60) ))
        {
          dval = dval / 60;
@@ -689,9 +706,10 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
 
 
 /**
- * "asctime", except for GNUnet time.
- * This is one of the very few calls in the entire API that is
- * NOT reentrant!
+ * "asctime", except for GNUnet time.  Converts a GNUnet internal
+ * absolute time (which is in UTC) to a string in local time.
+ * Note that the returned value will be overwritten if this function
+ * is called again.
  *
  * @param t time to convert
  * @return absolute time in human-readable format
@@ -756,7 +774,7 @@ getValue__ (unsigned char a)
  * Convert binary data to ASCII encoding.  The ASCII encoding is rather
  * GNUnet specific.  It was chosen such that it only uses characters
  * in [0-9A-V], can be produced without complex arithmetics and uses a
- * small number of characters.  
+ * small number of characters.
  * Does not append 0-terminator, but returns a pointer to the place where
  * it should be placed, if needed.
  *
@@ -771,7 +789,7 @@ char *
 GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out, size_t out_size)
 {
   /**
-   * 32 characters for encoding 
+   * 32 characters for encoding
    */
   static char *encTable__ = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
   unsigned int wpos;
@@ -1040,7 +1058,7 @@ GNUNET_STRINGS_path_is_absolute (const char *filename, int can_be_uri,
 
 /**
  * Perform 'checks' on 'filename'
- * 
+ *
  * @param filename file to check
  * @param checks checks to perform
  * @return GNUNET_YES if all checks pass, GNUNET_NO if at least one of them
@@ -1081,7 +1099,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
 /**
  * Tries to convert 'zt_addr' string to an IPv6 address.
  * The string is expected to have the format "[ABCD::01]:80".
- * 
+ *
  * @param zt_addr 0-terminated string. May be mangled by the function.
  * @param addrlen length of zt_addr (not counting 0-terminator).
  * @param r_buf a buffer to fill. Initially gets filled with zeroes,
@@ -1090,7 +1108,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
  *         case the contents of r_buf are undefined.
  */
 int
-GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 
+GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
                                uint16_t addrlen,
                                struct sockaddr_in6 *r_buf)
 {
@@ -1100,7 +1118,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
   unsigned int port;
 
   if (addrlen < 6)
-    return GNUNET_SYSERR;  
+    return GNUNET_SYSERR;
   memcpy (zbuf, zt_addr, addrlen);
   if ('[' != zbuf[0])
   {
@@ -1152,7 +1170,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
 /**
  * Tries to convert 'zt_addr' string to an IPv4 address.
  * The string is expected to have the format "1.2.3.4:80".
- * 
+ *
  * @param zt_addr 0-terminated string. May be mangled by the function.
  * @param addrlen length of zt_addr (not counting 0-terminator).
  * @param r_buf a buffer to fill.
@@ -1191,7 +1209,7 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen,
 /**
  * Tries to convert 'addr' string to an IP (v4 or v6) address.
  * Will automatically decide whether to treat 'addr' as v4 or v6 address.
- * 
+ *
  * @param addr a string, may not be 0-terminated.
  * @param addrlen number of bytes in addr (if addr is 0-terminated,
  *        0-terminator should not be counted towards addrlen).
@@ -1200,7 +1218,7 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen,
  *         case the contents of r_buf are undefined.
  */
 int
-GNUNET_STRINGS_to_address_ip (const char *addr, 
+GNUNET_STRINGS_to_address_ip (const char *addr,
                              uint16_t addrlen,
                              struct sockaddr_storage *r_buf)
 {