1 /* 2 * Copyright (c) 2004-2006 Maxim Sobolev <sobomax@FreeBSD.org> 3 * Copyright (c) 2006-2014 Sippy Software, Inc., http://www.sippysoft.com 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29 #ifndef _RTPP_UTIL_H_ 30 #define _RTPP_UTIL_H_ 31 32 #if !defined(PACKAGE_VERSION) 33 # error "config.h" needs to be included 34 #endif 35 36 #define NOT(x) (((x) == 0) ? 1 : 0) 37 38 struct cfg; 39 40 /* Function prototypes */ 41 void seedrandom(void); 42 int set_rlimits(struct cfg *); 43 int drop_privileges(struct cfg *); 44 char *rtpp_strsep(char **, const char *); 45 int rtpp_daemon(int, int); 46 int url_unquote(unsigned char *, int); 47 int rtpp_get_sched_hz(void); 48 long long rtpp_rlim_max(struct cfg *cf); 49 #ifndef HAVE_STRLCPY 50 size_t strlcpy(char *, const char *, size_t); 51 #endif 52 53 54 /* Some handy/compat macros */ 55 #if !defined(INFTIM) 56 #define INFTIM (-1) 57 #endif 58 59 #if !defined(ACCESSPERMS) 60 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) 61 #endif 62 #if !defined(DEFFILEMODE) 63 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 64 #endif 65 66 #if !defined(HAVE_ERR_H) 67 #define err(exitcode, format, args...) \ 68 errx(exitcode, format ": %s", ## args, strerror(errno)) 69 #define errx(exitcode, format, args...) \ 70 { warnx(format, ## args); exit(exitcode); } 71 #define warn(format, args...) \ 72 warnx(format ": %s", ## args, strerror(errno)) 73 #define warnx(format, args...) \ 74 fprintf(stderr, format "\n", ## args) 75 #endif 76 77 #endif 78