1 /* 2 * utils.h 3 * 4 * Oliver Fromme <olli@fromme.com> 5 * 6 * Copyright (C) 1997,1998,1999 7 * Oliver Fromme. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the author nor the names of any co-contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY OLIVER FROMME AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL OLIVER FROMME OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)$Id: utils.h,v 1.3 1999/01/01 23:32:06 olli Exp $ 34 */ 35 36 static const char cvsid_utils_h[] 37 = "@(#)$Id: utils.h,v 1.3 1999/01/01 23:32:06 olli Exp $"; 38 39 #include <stdlib.h> 40 41 typedef int bool; 42 #ifndef TRUE 43 #define FALSE 0 44 #define TRUE 1 45 #endif 46 47 extern char *me; 48 /* 49 * The name of the executable (without directory). 50 * Initialized by init(). 51 */ 52 53 void out_of_memory (void); 54 /* 55 * Prints the program name followed by a message that there 56 * is not enough memory (to stderr) and exits with code 1. 57 */ 58 59 void *tmalloc (size_t size); 60 /* 61 * Wrapper for malloc() which checks the result and calls 62 * out_of_memory() if the requested memory could not be 63 * allocated. 64 */ 65 66 #if defined(__FreeBSD__) 67 #include <osreldate.h> 68 #if __FreeBSD_version <= 800057 && __FreeBSD_version > 800000 || __FreeBSD_version <= 701100 69 char *strndup (char *src, int num); 70 /* 71 * Like strdup(), but limits the string length to at most 72 * <num> characters (not counting the terminating zero). 73 * The resulting string is always zero-terminated. 74 * Always allocates <num>+1 bytes, even if less space would 75 * be sufficient to store <src>. 76 */ 77 #endif 78 #endif 79 80 char *justify (char *str); 81 /* 82 * Removes leading and trailing whitespace, and compresses 83 * contained whitespace to single spaces. Returns <str>. 84 * Whitespace is a sequence of ' ', '\t', '\r' and/or '\n'. 85 */ 86 87 void die (const char *func); 88 /* 89 * Prints the executable name, func, and the error string 90 * corresponding to errno to stdout, followed by a newline, 91 * and exits the program with code 1 (failure). 92 */ 93 94 void utils_init (char *argv0); 95 /* 96 * Initializes *me. Should be the first instruction in 97 * main(), with argv[0] as parameter. 98 */ 99 100 /* EOF */ 101