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