-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcompat.h
213 lines (190 loc) · 5.52 KB
/
compat.h
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
/*
* Header file for compatibility functions.
*
* Copyright 2000 by Gray Watson
*
* This file is part of the dmalloc package.
*
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies, and that the name of Gray Watson not be used in advertising
* or publicity pertaining to distribution of the document or software
* without specific, written prior permission.
*
* Gray Watson makes no representations about the suitability of the
* software described herein for any purpose. It is provided "as is"
* without express or implied warranty.
*
* The author may be contacted via http://dmalloc.com/
*
* $Id: compat.h,v 1.42 2007/05/14 15:53:11 gray Exp $
*/
#ifndef __COMPAT_H__
#define __COMPAT_H__
#if HAVE_STDARG_H
# include <stdarg.h> /* for ... */
#endif
#include "conf.h" /* for HAVE... */
/*<<<<<<<<<< The below prototypes are auto-generated by fillproto */
#if HAVE_ATOI == 0
/*
* Turn a ascii-string into an integer which is returned
*/
extern
int atoi(const char *str);
#endif /* if HAVE_ATOI == 0 */
#if HAVE_ATOL == 0
/*
* Turn a ascii-string into an integer which is returned
*/
extern
long atol(const char *str);
#endif /* if HAVE_ATOL == 0 */
/*
* Local ascii to unsigned long function
*/
extern
unsigned long loc_atoul(const char *str);
/*
* Local vsnprintf which handles the buffer-size or not. Returns the
* number of characters copied into BUF.
*/
extern
int loc_vsnprintf(char *buf, const int buf_size, const char *format,
va_list args);
/*
* Local snprintf which handles the buf-size not. Returns the number
* of characters copied into BUF.
*/
extern
int loc_snprintf(char *buf, const int buf_size, const char *format, ...);
#if HAVE_MEMCMP == 0
/*
* Compare LEN characters, return -1,0,1 if STR1 is <,==,> STR2
*/
extern
int memcmp(const void *str1, const void *str2, DMALLOC_SIZE len);
#endif /* if HAVE_MEMCMP == 0 */
#if HAVE_MEMCPY == 0
/*
* Copy LEN characters from SRC to DEST
*/
extern
void *memcpy(void *dest, const void *src, DMALLOC_SIZE len);
#endif /* if HAVE_MEMCPY == 0 */
#if HAVE_MEMMOVE == 0
/*
* Copy LEN characters from SRC to DEST
*/
extern
void *memmove(void *dest, const void *src, DMALLOC_SIZE len);
#endif /* if HAVE_MEMMOVE == 0 */
#if HAVE_MEMSET == 0
/*
* Set LEN characters in STR to character CH
*/
extern
void *memset(void *str, const int ch, DMALLOC_SIZE len);
#endif /* if HAVE_MEMSET == 0 */
#if HAVE_STRCHR == 0
/*
* Find CH in STR by searching backwards through the string
*/
extern
char *strchr(const char *str, const int ch);
#endif /* if HAVE_STRCHR == 0 */
#if HAVE_STRCMP == 0
/*
* Returns -1,0,1 on whether STR1 is <,==,> STR2
*/
extern
int strcmp(const char *str1, const char *str2);
#endif /* if HAVE_STRCMP == 0 */
#if HAVE_STRCPY == 0
/*
* Copies STR2 to STR1. Returns STR1.
*/
extern
char *strcpy(char *str1, const char *str2);
#endif /* if HAVE_STRCPY == 0 */
#if HAVE_STRLEN == 0
/*
* Return the length in characters of STR
*/
extern
int strlen(const char *str);
#endif /* if HAVE_STRLEN == 0 */
#if HAVE_STRNCMP == 0
/*
* Compare at most LEN chars in STR1 and STR2 and return -1,0,1 or
* STR1 - STR2
*/
extern
int strncmp(const char *str1, const char *str2, const int len);
#endif /* if HAVE_STRNCMP == 0 */
#if HAVE_STRNCPY == 0
/*
* Copy STR2 to STR1 until LEN or null
*/
extern
char *strncpy(char *str1, const char *str2, const int len);
#endif /* if HAVE_STRNCPY == 0 */
#if HAVE_STRRCHR == 0
/*
* Find CH in STR by searching backwards through the string
*/
extern
char *strrchr(const char *str, const int ch);
#endif /* if HAVE_STRRCHR == 0 */
#if HAVE_STRSEP == 0
/*
* char *strsep
*
* DESCRIPTION:
*
* This is a function which should be in libc in every Unix. Grumble.
* It basically replaces the strtok function because it is reentrant.
* This tokenizes a string by returning the next token in a string and
* punching a \0 on the first delimiter character past the token. The
* difference from strtok is that you pass in the address of a string
* pointer which will be shifted allong the buffer being processed.
* With strtok you passed in a 0L for subsequant calls. Yeach.
*
* This will count the true number of delimiter characters in the string
* and will return an empty token (one with \0 in the zeroth position)
* if there are two delimiter characters in a row.
*
* Consider the following example:
*
* char *tok, *str_p = "1,2,3, hello there ";
*
* while (1) { tok = strsep(&str_p, " ,"); if (tok == 0L) { break; } }
*
* strsep will return as tokens: "1", "2", "3", "", "hello", "there", "".
* Notice the two empty "" tokens where there were two delimiter
* characters in a row ", " and at the end of the string where there
* was an extra delimiter character. If you want to ignore these
* tokens then add a test to see if the first character of the token
* is \0.
*
* RETURNS:
*
* Success - Pointer to the next delimited token in the string.
*
* Failure - 0L if there are no more tokens.
*
* ARGUMENTS:
*
* string_p - Pointer to a string pointer which will be searched for
* delimiters. \0's will be added to this buffer.
*
* delim - List of delimiter characters which separate our tokens. It
* does not have to remain constant through all calls across the same
* string.
*/
extern
char *strsep(char **string_p, const char *delim);
#endif /* if HAVE_STRSEP == 0 */
/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
#endif /* ! __COMPAT_H__ */