2 * uhttpd - Tiny single-threaded httpd
4 * Copyright (C) 2010-2013 Jo-Philipp Wich <xm@subsignal.org>
5 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #ifndef _UHTTPD_UTILS_
44 #define min(x, y) (((x) < (y)) ? (x) : (y))
45 #define max(x, y) (((x) > (y)) ? (x) : (y))
47 #define array_size(x) \
48 (sizeof(x) / sizeof(x[0]))
50 #define fd_cloexec(fd) \
51 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)
54 static inline void clearenv(void)
56 extern char **environ;
60 time_t timegm (struct tm *tm);
65 #define __printf(a, b) __attribute__((format(printf, a, b)))
67 #define __printf(a, b)
70 int uh_urldecode(char *buf, int blen, const char *src, int slen);
71 int uh_urlencode(char *buf, int blen, const char *src, int slen);
72 int uh_b64decode(char *buf, int blen, const void *src, int slen);
73 bool uh_path_match(const char *prefix, const char *url);
74 char *uh_split_header(char *str);
75 bool uh_addr_rfc1918(struct uh_addr *addr);
76 char *uh_htmlescape(const char *src);