[go: up one dir, main page]

Menu

[r456]: / tags / start / src / common.c  Maximize  Restore  History

Download this file

243 lines (201 with data), 3.4 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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* -------------------------------------------------------
* Copyright (C) 2002-2003 Tommi Saviranta <tsaviran@cs.helsinki.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.
*/
#include <string.h>
#include <stdlib.h>
#include "miau.h"
#include "tools.h"
#include "messages.h"
#include "log.h"
#include "irc.h"
#define REPORT_ERROR(func) error(ERR_UNEXPECTED, func, file, line);
int
_xstrcmp(
const char *s1,
const char *s2
DEBUG_ADDPARMS
)
{
if (s1 != NULL && s2 != NULL) {
return strcmp(s1, s2);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrcmp");
#endif
return 1;
}
}
int
_xstrncmp(
const char *s1,
const char *s2,
size_t n
DEBUG_ADDPARMS
)
{
if (s1 != NULL && s2 != NULL) {
return strncmp(s1, s2, n);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrncmp");
#endif
return 1;
}
}
int
_xstrcasecmp(
const char *s1,
const char *s2
DEBUG_ADDPARMS
)
{
if (s1 != NULL && s2 != NULL) {
return strcasecmp(s1, s2);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrcasecmp");
#endif
return 1;
}
}
int
_xstrncasecmp(
const char *s1,
const char *s2,
size_t n
DEBUG_ADDPARMS
)
{
if (s1 != NULL && s2 != NULL) {
return strncasecmp(s1, s2, n);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrncasecmp");
#endif
return 1;
}
}
char *
_xstrcpy(
char *dest,
const char *src
DEBUG_ADDPARMS
)
{
if (dest != NULL && src != NULL) {
return strcpy(dest, src);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrcpy");
#endif
return 0;
}
}
char *
_xstrncpy(
char *dest,
const char *src,
size_t n
DEBUG_ADDPARMS
)
{
if (dest != NULL && src != NULL) {
return strncpy(dest, src, n);
} else {
#ifdef DEBUG_ADDPARMS
REPORT_ERROR("xstrncpy");
#endif
return 0;
}
}
void *
xmalloc(
size_t size
)
{
void *ret = malloc(size);
if (ret == NULL) {
error(ERR_MEMORY);
escape();
}
return ret;
}
void *
xcalloc(
size_t nmemb,
size_t size
)
{
void *ret = calloc(nmemb, size);
if (ret == NULL) {
error(ERR_MEMORY);
escape();
}
return ret;
}
void
xfree(
void *ptr
)
{
if (ptr != NULL) {
free(ptr);
}
}
/*
void
xnullfree(
void **ptr
)
{
if (*ptr != NULL) {
free(*ptr);
}
*ptr = NULL;
}
*/
void *
xrealloc(
void *ptr,
size_t size
)
{
void *ret = realloc(ptr, size);
if (ret == NULL && size > 0) {
error(ERR_MEMORY);
escape();
}
return ret;
}
#ifdef ENDUSERDEBUG
void
enduserdebug(
char *format,
...
)
{
va_list va;
char buf0[BUFFERSIZE];
char buf1[BUFFERSIZE + 160];
va_start(va, format);
vsnprintf(buf0, BUFFERSIZE - 1, format, va);
va_end(va);
if (c_clients.connected > 0) {
sprintf(buf1, ":debug PRIVMSG %s :%s: %s", status.nickname,
log_get_timestamp(), buf0);
irc_mwrite(&c_clients, "%s", buf1);
}
}
#endif /* ENDUSERDEBUG */