2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_strings_lib.h
23 * @brief strings and string handling functions (including malloc
24 * and string tokenizing)
26 * @author Christian Grothoff
27 * @author Krista Bennett
28 * @author Gerd Knorr <kraxel@bytesex.org>
29 * @author Ioana Patrascu
30 * @author Tzvetan Horozov
33 #ifndef GNUNET_STRINGS_LIB_H
34 #define GNUNET_STRINGS_LIB_H
36 /* we need size_t, and since it can be both unsigned int
37 or unsigned long long, this IS platform dependent;
38 but "stdlib.h" should be portable 'enough' to be
39 unconditionally available... */
45 #if 0 /* keep Emacsens' auto-indent happy */
50 #include "gnunet_time_lib.h"
54 * Convert a given filesize into a fancy human-readable format.
56 * @param size number of bytes
57 * @return fancy representation of the size (possibly rounded) for humans
59 char *GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
63 * Convert the len characters long character sequence
64 * given in input that is in the given charset
67 * @param input the input string (not necessarily 0-terminated)
68 * @param len the number of bytes in the input
69 * @param charset character set to convert from
70 * @return the converted string (0-terminated)
72 char *GNUNET_STRINGS_to_utf8 (const char *input,
73 size_t len, const char *charset);
77 * Complete filename (a la shell) from abbrevition.
79 * @param fil the name of the file, may contain ~/ or
80 * be relative to the current directory
81 * @return the full file name,
82 * NULL is returned on error
84 char *GNUNET_STRINGS_filename_expand (const char *fil);
87 * Fill a buffer of the given size with
88 * count 0-terminated strings (given as varargs).
89 * If "buffer" is NULL, only compute the amount of
90 * space required (sum of "strlen(arg)+1").
92 * Unlike using "snprintf" with "%s", this function
93 * will add 0-terminators after each string. The
94 * "GNUNET_string_buffer_tokenize" function can be
95 * used to parse the buffer back into individual
98 * @param buffer the buffer to fill with strings, can
99 * be NULL in which case only the necessary
100 * amount of space will be calculated
101 * @param size number of bytes available in buffer
102 * @param count number of strings that follow
103 * @param ... count 0-terminated strings to copy to buffer
104 * @return number of bytes written to the buffer
105 * (or number of bytes that would have been written)
107 size_t GNUNET_STRINGS_buffer_fill (char *buffer,
108 size_t size, unsigned int count, ...);
112 * Given a buffer of a given size, find "count"
113 * 0-terminated strings in the buffer and assign
114 * the count (varargs) of type "const char**" to the
115 * locations of the respective strings in the
118 * @param buffer the buffer to parse
119 * @param size size of the buffer
120 * @param count number of strings to locate
121 * @param ... pointers to where to store the strings
122 * @return offset of the character after the last 0-termination
123 * in the buffer, or 0 on error.
125 unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer,
127 unsigned int count, ...);
132 * "man ctime_r", except for GNUnet time; also, unlike ctime, the
133 * return value does not include the newline character.
135 * @param t the absolute time to convert
136 * @return timestamp in human-readable form
138 char *GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
142 * Give relative time in human-readable fancy format.
144 * @param delta time in milli seconds
145 * @return string in human-readable form
147 char *GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative
150 #if 0 /* keep Emacsens' auto-indent happy */
158 /* ifndef GNUNET_UTIL_STRING_H */
160 /* end of gnunet_util_string.h */