[go: up one dir, main page]

Menu

[r456]: / tags / 0.6.4 / src / common.h  Maximize  Restore  History

Download this file

93 lines (71 with data), 3.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* $Id$
* -------------------------------------------------------
* Copyright (C) 2003-2006 Tommi Saviranta <wnd@iki.fi>
* (C) 2002 Sebastian Kienzl <zap@riot.org>
* -------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef COMMON_H_
#define COMMON_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* ifdef HAVE_CONFIG_H */
#include <stdlib.h>
/* Error codes. */
#define ERR_CODE_HOME 2
#define ERR_CODE_CONFIG 3
#define ERR_CODE_NETWORK 4
#define ERR_CODE_LOG 5
#define ERR_CODE_MEMORY 9
/* Only if preprocessor supports __FILE__/__LINE__-stuff. */
#ifdef __FILE__
#define xstrcmp(s1, s2) _xstrcmp(s1, s2, __FILE__, __LINE__)
#define xstrncmp(s1, s2, n) _xstrncmp(s1, s2, n, __FILE__, __LINE__)
#define xstrcasecmp(s1, s2) _xstrcasecmp(s1, s2, __FILE__, __LINE__)
#define xstrncasecmp(s1, s2, n) _xstrncasecmp(s1, s2, n, __FILE__, __LINE__)
#define xstrcpy(dest, src) _xstrcpy(dest, src, __FILE__, __LINE__)
#define xstrncpy(dest, src, n) _xstrncpy(dest, src, n, __FILE__, __LINE__)
#define xstrdup(s) _xstrdup(s, __FILE__, __LINE__)
#define DEBUG_ADDPARMS , const char *file, const int line
#else /* ifdef __FILE__ */
#define xstrcmp(s1, s2) _xstrcmp(s1, s2)
#define xstrncmp(s1, s2, n) _xstrncmp(s1, s2)
#define xstrcasecmp(s1, s2) _xstrcasecmp(s1, s2)
#define xstrncasecmp(s1, s2, n) _xstrncasecmp(s1, s2, n)
#define xstrcpy(dest, src) _xstrcpy(dest, src)
#define xstrncpy(dest, src, n) _xstrncpy(dest, src, n)
#define xstrdup(s) _strdup(s)
#endif /*ifdef else __FILE__ */
int _xstrcmp(const char *s1, const char *s2 DEBUG_ADDPARMS);
int _xstrncmp(const char *s1, const char *s2, size_t n DEBUG_ADDPARMS);
int _xstrcasecmp(const char *s1, const char *s2 DEBUG_ADDPARMS);
int _xstrncasecmp(const char *s1, const char *s2, size_t n DEBUG_ADDPARMS);
char *_xstrcpy(char *dest, const char *src DEBUG_ADDPARMS);
char *_xstrncpy(char *dest, const char *src, size_t n DEBUG_ADDPARMS);
char *_xstrdup(const char *s DEBUG_ADDPARMS);
void *xmalloc(size_t size);
void *xcalloc(size_t, size_t);
void xfree(void *ptr);
/* void xnullfree(void **ptr); */
void *xrealloc(void *ptr, size_t size);
/* #define FREE(ptr) xnullfree((void *) &ptr) */
#define FREE(ptr) { xfree(ptr); ptr = NULL; }
#ifndef HAVE_VSNPRINTF
#include <stdio.h>
#include <stdarg.h>
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif /* ifndef HAVE_VSNPRINTF */
#ifndef HAVE_SNPRINTF
#include <stdio.h>
#include <stdarg.h>
int snprintf(char *str, size_t size, const char *format, ...);
#endif /* ifndef HAVE_SNPRINTF */
#endif /* ifndef COMMON_H_ */