1/* Declarations for utils.c. 2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 3 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 4 5This file is part of GNU Wget. 6 7GNU Wget is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 3 of the License, or 10(at your option) any later version. 11 12GNU Wget is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with Wget. If not, see <http://www.gnu.org/licenses/>. 19 20Additional permission under GNU GPL version 3 section 7 21 22If you modify this program, or any covered work, by linking or 23combining it with the OpenSSL project's OpenSSL library (or a 24modified version of that library), containing parts covered by the 25terms of the OpenSSL or SSLeay licenses, the Free Software Foundation 26grants you additional permission to convey the resulting work. 27Corresponding Source for a non-source form of such a combination 28shall include the source code for the parts of OpenSSL used as well 29as that of the covered work. */ 30 31#ifndef UTILS_H 32#define UTILS_H 33 34/* Constant is using when we don`t know attempted size exactly */ 35#define UNKNOWN_ATTEMPTED_SIZE -3 36 37/* Macros that interface to malloc, but know about type sizes, and 38 cast the result to the appropriate type. The casts are not 39 necessary in standard C, but Wget performs them anyway for the sake 40 of pre-standard environments and possibly C++. */ 41 42#define xnew(type) (xmalloc (sizeof (type))) 43#define xnew0(type) (xcalloc (1, sizeof (type))) 44#define xnew_array(type, len) (xmalloc ((len) * sizeof (type))) 45#define xnew0_array(type, len) (xcalloc ((len), sizeof (type))) 46 47#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type))) 48 49#define xfree free 50/* Free P if it is non-NULL. C requires free() to behaves this way by 51 default, but Wget's code is historically careful not to pass NULL 52 to free. This allows us to assert p!=NULL in xfree to check 53 additional errors. (But we currently don't do that!) */ 54#define xfree_null(p) if (!(p)) ; else xfree (p) 55 56struct hash_table; 57 58struct file_memory { 59 char *content; 60 long length; 61 int mmap_p; 62}; 63 64#define HYPHENP(x) (*(x) == '-' && !*((x) + 1)) 65 66char *time_str (time_t); 67char *datetime_str (time_t); 68 69char *xstrdup_lower (const char *); 70 71char *strdupdelim (const char *, const char *); 72char **sepstring (const char *); 73bool subdir_p (const char *, const char *); 74void fork_to_background (void); 75 76char *aprintf (const char *, ...) GCC_FORMAT_ATTR (1, 2); 77char *concat_strings (const char *, ...); 78 79void touch (const char *, time_t); 80int remove_link (const char *); 81bool file_exists_p (const char *); 82bool file_non_directory_p (const char *); 83wgint file_size (const char *); 84int make_directory (const char *); 85char *unique_name (const char *, bool); 86FILE *unique_create (const char *, bool, char **); 87FILE *fopen_excl (const char *, int); 88char *file_merge (const char *, const char *); 89 90int fnmatch_nocase (const char *, const char *, int); 91bool acceptable (const char *); 92bool accdir (const char *s); 93char *suffix (const char *s); 94bool match_tail (const char *, const char *, bool); 95bool has_wildcards_p (const char *); 96 97bool has_html_suffix_p (const char *); 98 99char *read_whole_line (FILE *); 100struct file_memory *read_file (const char *); 101void read_file_free (struct file_memory *); 102 103void free_vec (char **); 104char **merge_vecs (char **, char **); 105char **vec_append (char **, const char *); 106 107void string_set_add (struct hash_table *, const char *); 108int string_set_contains (struct hash_table *, const char *); 109void string_set_to_array (struct hash_table *, char **); 110void string_set_free (struct hash_table *); 111void free_keys_and_values (struct hash_table *); 112 113const char *with_thousand_seps (wgint); 114 115/* human_readable must be able to accept wgint and SUM_SIZE_INT 116 arguments. On machines where wgint is 32-bit, declare it to accept 117 double. */ 118#if SIZEOF_WGINT >= 8 119# define HR_NUMTYPE wgint 120#else 121# define HR_NUMTYPE double 122#endif 123char *human_readable (HR_NUMTYPE); 124 125 126int numdigit (wgint); 127char *number_to_string (char *, wgint); 128char *number_to_static_string (wgint); 129 130int determine_screen_width (void); 131int random_number (int); 132double random_float (void); 133 134bool run_with_timeout (double, void (*) (void *), void *); 135void xsleep (double); 136 137/* How many bytes it will take to store LEN bytes in base64. */ 138#define BASE64_LENGTH(len) (4 * (((len) + 2) / 3)) 139 140int base64_encode (const void *, int, char *); 141int base64_decode (const char *, void *); 142 143void stable_sort (void *, size_t, size_t, int (*) (const void *, const void *)); 144 145const char *print_decimal (double); 146 147extern unsigned char char_prop[]; 148 149#endif /* UTILS_H */ 150