1 /*****************************************************************
3 ** @(#) misc.h (c) 2005 - 2007 Holger Zuleger hznet.de
5 ** Copyright (c) 2005 - 2007, Holger Zuleger HZnet. All rights reserved.
7 ** This software is open source.
9 ** Redistribution and use in source and binary forms, with or without
10 ** modification, are permitted provided that the following conditions
13 ** Redistributions of source code must retain the above copyright notice,
14 ** this list of conditions and the following disclaimer.
16 ** Redistributions in binary form must reproduce the above copyright notice,
17 ** this list of conditions and the following disclaimer in the documentation
18 ** and/or other materials provided with the distribution.
20 ** Neither the name of Holger Zuleger HZnet nor the names of its contributors may
21 ** be used to endorse or promote products derived from this software without
22 ** specific prior written permission.
24 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
28 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 ** POSSIBILITY OF SUCH DAMAGE.
36 *****************************************************************/
39 # include <sys/types.h>
44 # define min(a, b) ((a) < (b) ? (a) : (b))
45 # define max(a, b) ((a) > (b) ? (a) : (b))
47 extern const char *getnameappendix (const char *progname, const char *basename);
48 extern const char *getdefconfname (const char *view);
49 extern int fileexist (const char *name);
50 extern size_t filesize (const char *name);
51 extern int file_age (const char *fname);
52 extern int touch (const char *fname, time_t sec);
53 extern int linkfile (const char *fromfile, const char *tofile);
54 //extern int copyfile (const char *fromfile, const char *tofile);
55 extern int copyfile (const char *fromfile, const char *tofile, const char *dnskeyfile);
56 extern int copyzonefile (const char *fromfile, const char *tofile, const char *dnskeyfile);
57 extern int cmpfile (const char *file1, const char *file2);
58 extern char *str_delspace (char *s);
60 extern char *domain_canonicdup (const char *s);
62 extern char *str_tolowerdup (const char *s);
64 extern int in_strarr (const char *str, char *const arr[], int cnt);
65 extern const char *splitpath (char *path, size_t size, const char *filename);
66 extern char *pathname (char *name, size_t size, const char *path, const char *file, const char *ext);
67 extern char *time2str (time_t sec, int precision);
68 extern char *time2isostr (time_t sec, int precision);
69 extern time_t timestr2time (const char *timestr);
70 extern int is_keyfilename (const char *name);
71 extern int is_directory (const char *name);
72 extern time_t file_mtime (const char *fname);
73 extern int is_exec_ok (const char *prog);
74 extern char *age2str (time_t sec);
75 extern time_t stop_timer (time_t start);
76 extern time_t start_timer (void);
77 extern void error (char *fmt, ...);
78 extern void fatal (char *fmt, ...);
79 extern void logmesg (char *fmt, ...);
80 extern void verbmesg (int verblvl, const zconf_t *conf, char *fmt, ...);
81 extern void logflush (void);
82 extern int inc_serial (const char *fname, int use_unixtime);
83 extern const char *inc_errstr (int err);
84 extern char *str_untaint (char *str);
85 extern char *str_chop (char *str, char c);
86 extern int is_dotfile (const char *name);
87 extern void parseurl (char *url, char **proto, char **host, char **port, char **para);