ekg2
|
00001 /* $Id$ */ 00002 00003 /* 00004 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl> 00005 * 2004 Piotr Kupisiewicz <deli@rzepaknet.us> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License Version 2 as 00009 * published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __EKG_XMALLOC_H 00022 #define __EKG_XMALLOC_H 00023 00024 #include <sys/types.h> 00025 #include <stddef.h> 00026 #include <stdarg.h> 00027 00028 #ifndef __USE_POSIX 00029 #define __USE_POSIX 1 /* glibc 2.8 */ 00030 #endif 00031 #ifndef _XOPEN_SOURCE 00032 #define _XOPEN_SOURCE 600 00033 #endif 00034 #include <limits.h> 00035 00036 #define __(x) (x ? x : "(null)") 00037 00038 /* stolen from: http://sourcefrog.net/weblog/software/languages/C/unused.html */ 00039 #ifdef UNUSED 00040 #elif defined(__GNUC__) 00041 # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) 00042 #elif defined(__LCLINT__) 00043 # define UNUSED(x) /*@unused@*/ x 00044 #else 00045 # define UNUSED(x) x 00046 #endif 00047 /* /stolen */ 00048 00049 #ifndef HAVE_SOCKLEN_T 00050 typedef unsigned int socklen_t; 00051 #endif 00052 00053 /* buffer lengths in stuff.c */ 00054 #ifndef PATH_MAX 00055 # ifdef MAX_PATH 00056 # define PATH_MAX MAX_PATH 00057 # else 00058 # ifdef _POSIX_PATH_MAX 00059 # define PATH_MAX _POSIX_PATH_MAX 00060 # else 00061 # define PATH_MAX 4096 00062 # endif 00063 # endif 00064 #endif 00065 00066 #ifndef EKG2_WIN32_NOFUNCTION 00067 00068 void ekg_oom_handler(); 00069 00070 void *xcalloc(size_t nmemb, size_t size); 00071 void *xmalloc(size_t size); 00072 void xfree(void *ptr); 00073 void *xrealloc(void *ptr, size_t size); 00074 char *xstrdup(const char *s); 00075 size_t xstrnlen(const char *s, size_t n); 00076 char *xstrndup(const char *s, size_t n); 00077 char *utf8ndup(const char *s, size_t n); 00078 void *xmemdup(void *ptr, size_t size); 00079 00080 int xstrcasecmp(const char *s1, const char *s2); 00081 char *xstrcat(char *dest, const char *src); 00082 char *xstrchr(const char *s, int c); 00083 int xstrcmp(const char *s1, const char *s2); 00084 int xstrcoll(const char *s1, const char *s2); 00085 char *xstrcpy(char *dest, const char *src); 00086 size_t xstrcspn(const char *s, const char *reject); 00087 char *xstrfry(char *string); 00088 size_t xstrlen(const char *s); 00089 int xstrncasecmp_pl(const char *s1, const char *s2, size_t n); 00090 char *xstrncat(char *dest, const char *src, size_t n); 00091 int xstrncmp(const char *s1, const char *s2, size_t n); 00092 char *xstrncpy(char *dest, const char *src, size_t n); 00093 int xstrncasecmp(const char *s1, const char *s2, size_t n); 00094 char *xstrpbrk(const char *s, const char *accept); 00095 char *xstrrchr(const char *s, int c); 00096 /* 00097 char *xstrsep(char **stringp, const char *delim); 00098 */ 00099 size_t xstrspn(const char *s, const char *accept); 00100 char *xstrstr(const char *haystack, const char *needle); 00101 char *xstrcasestr(const char *haystack, const char *needle); 00102 char *xstrtok(char *s, const char *delim); 00103 char *xindex(const char *s, int c); 00104 char *xrindex(const char *s, int c); 00105 00106 char *vsaprintf(const char *format, va_list ap); 00107 00108 /* stuff.h */ 00109 #ifdef __GNUC__ 00110 char *saprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 00111 #else 00112 char *saprintf(const char *format, ...); 00113 #endif 00114 #endif 00115 00116 00117 #endif /* __EKG_XMALLOC_H */ 00118 00119 /* 00120 * Local Variables: 00121 * mode: c 00122 * c-file-style: "k&r" 00123 * c-basic-offset: 8 00124 * indent-tabs-mode: t 00125 * End: 00126 */