]> sjero.net Git - wget/blob - src/utils.h
Merge from mainline
[wget] / src / utils.h
1 /* Declarations for utils.c.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3    2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GNU Wget.
6
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Wget.  If not, see <http://www.gnu.org/licenses/>.
19
20 In addition, as a special exception, the Free Software Foundation
21 gives permission to link the code of its release of Wget with the
22 OpenSSL project's "OpenSSL" library (or with modified versions of it
23 that use the same license as the "OpenSSL" library), and distribute
24 the linked executables.  You must obey the GNU General Public License
25 in all respects for all of the code used other than "OpenSSL".  If you
26 modify this file, you may extend this exception to your version of the
27 file, but you are not obligated to do so.  If you do not wish to do
28 so, delete this exception statement from your version.  */
29
30 #ifndef UTILS_H
31 #define UTILS_H
32
33 struct hash_table;
34
35 struct file_memory {
36   char *content;
37   long length;
38   int mmap_p;
39 };
40
41 #define HYPHENP(x) (*(x) == '-' && !*((x) + 1))
42
43 char *time_str (time_t);
44 char *datetime_str (time_t);
45
46 #ifdef DEBUG_MALLOC
47 void print_malloc_debug_stats ();
48 #endif
49
50 char *xstrdup_lower (const char *);
51
52 char *strdupdelim (const char *, const char *);
53 char **sepstring (const char *);
54 bool subdir_p (const char *, const char *);
55 void fork_to_background (void);
56
57 char *aprintf (const char *, ...) GCC_FORMAT_ATTR (1, 2);
58 char *concat_strings (const char *, ...);
59
60 void touch (const char *, time_t);
61 int remove_link (const char *);
62 bool file_exists_p (const char *);
63 bool file_non_directory_p (const char *);
64 wgint file_size (const char *);
65 int make_directory (const char *);
66 char *unique_name (const char *, bool);
67 FILE *unique_create (const char *, bool, char **);
68 FILE *fopen_excl (const char *, bool);
69 char *file_merge (const char *, const char *);
70
71 int fnmatch_nocase (const char *, const char *, int);
72 bool acceptable (const char *);
73 bool accdir (const char *s);
74 char *suffix (const char *s);
75 bool match_tail (const char *, const char *, bool);
76 bool has_wildcards_p (const char *);
77
78 bool has_html_suffix_p (const char *);
79
80 char *read_whole_line (FILE *);
81 struct file_memory *read_file (const char *);
82 void read_file_free (struct file_memory *);
83
84 void free_vec (char **);
85 char **merge_vecs (char **, char **);
86 char **vec_append (char **, const char *);
87
88 void string_set_add (struct hash_table *, const char *);
89 int string_set_contains (struct hash_table *, const char *);
90 void string_set_to_array (struct hash_table *, char **);
91 void string_set_free (struct hash_table *);
92 void free_keys_and_values (struct hash_table *);
93
94 const char *with_thousand_seps (wgint);
95
96 /* human_readable must be able to accept wgint and SUM_SIZE_INT
97    arguments.  On machines where wgint is 32-bit, declare it to accept
98    double.  */
99 #if SIZEOF_WGINT >= 8
100 # define HR_NUMTYPE wgint
101 #else
102 # define HR_NUMTYPE double
103 #endif
104 char *human_readable (HR_NUMTYPE);
105
106
107 int numdigit (wgint);
108 char *number_to_string (char *, wgint);
109 char *number_to_static_string (wgint);
110
111 int determine_screen_width (void);
112 int random_number (int);
113 double random_float (void);
114
115 bool run_with_timeout (double, void (*) (void *), void *);
116 void xsleep (double);
117
118 /* How many bytes it will take to store LEN bytes in base64.  */
119 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
120
121 int base64_encode (const void *, int, char *);
122 int base64_decode (const char *, void *);
123
124 void stable_sort (void *, size_t, size_t, int (*) (const void *, const void *));
125
126 const char *print_decimal (double);
127
128 #endif /* UTILS_H */