![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
compat.h File Reference
Definition in file compat.h.
#include "asterisk/autoconfig.h"
#include <inttypes.h>
#include <sys/types.h>
#include <stdarg.h>
Include dependency graph for compat.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| int | asprintf (char **str, const char *fmt,...) |
| int | getloadavg (double *list, int nelem) |
| Return something that won't cancel the call, but still return -1, in case we correct the implementation to check return value. | |
| int | setenv (const char *name, const char *value, int overwrite) |
| char * | strcasestr (const char *, const char *) |
| char * | strndup (const char *, size_t) |
| size_t | strnlen (const char *, size_t) |
| char * | strsep (char **str, const char *delims) |
| uint64_t | strtoq (const char *nptr, char **endptr, int base) |
| Convert a string to a quad integer. | |
| int | unsetenv (const char *name) |
| int | vasprintf (char **strp, const char *fmt, va_list ap) |
|
||||||||||||||||
|
Definition at line 194 of file strcompat.c. References vasprintf. 00195 { 00196 va_list ap; 00197 int ret; 00198 00199 *str = NULL; 00200 va_start(ap, fmt); 00201 ret = vasprintf(str, fmt, ap); 00202 va_end(ap); 00203 00204 return ret; 00205 }
|
|
||||||||||||
|
Return something that won't cancel the call, but still return -1, in case we correct the implementation to check return value.
Definition at line 333 of file strcompat.c. Referenced by increase_call_count(). 00334 { 00335 int i; 00336 00337 for (i = 0; i < nelem; i++) { 00338 list[i] = 0.1; 00339 } 00340 return -1; 00341 }
|
|
||||||||||||||||
|
Definition at line 62 of file strcompat.c. Referenced by launch_script(), load_odbc_config(), read_environment(), reload(), and unsetenv(). 00063 { 00064 unsigned char *buf; 00065 int buflen; 00066 00067 buflen = strlen(name) + strlen(value) + 2; 00068 buf = alloca(buflen); 00069 00070 if (!overwrite && getenv(name)) 00071 return 0; 00072 00073 snprintf(buf, buflen, "%s=%s", name, value); 00074 00075 return putenv(buf); 00076 }
|
|
||||||||||||
|
Definition at line 101 of file strcompat.c. References offset, and upper(). Referenced by find_sdp(), find_via_branch(), get_rdnis(), get_refer_info(), gettag(), handle_request_invite(), handle_show_applications(), modlist_modentry(), parse_register_contact(), reqprep(), respprep(), and word_match(). 00102 { 00103 char *u1, *u2; 00104 int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1; 00105 00106 u1 = alloca(u1len); 00107 u2 = alloca(u2len); 00108 if (u1 && u2) { 00109 char *offset; 00110 if (u2len > u1len) { 00111 /* Needle bigger than haystack */ 00112 return NULL; 00113 } 00114 offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len)); 00115 if (offset) { 00116 /* Return the offset into the original string */ 00117 return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1))); 00118 } else { 00119 return NULL; 00120 } 00121 } else { 00122 return NULL; 00123 } 00124 }
|
|
||||||||||||
|
Definition at line 141 of file strcompat.c. References len, malloc, and strnlen(). 00142 { 00143 size_t len = strnlen(s, n); 00144 char *new = malloc(len + 1); 00145 00146 if (!new) 00147 return NULL; 00148 00149 new[len] = '\0'; 00150 return memcpy(new, s, len); 00151 }
|
|
||||||||||||
|
Definition at line 128 of file strcompat.c. References len. Referenced by strndup(). 00129 { 00130 size_t len; 00131 00132 for (len = 0; len < n; len++) 00133 if (s[len] == '\0') 00134 break; 00135 00136 return len; 00137 }
|
|
||||||||||||
|
||||||||||||||||
|
Convert a string to a quad integer.
Definition at line 224 of file strcompat.c. References LONG_MAX, LONG_MIN, and s. 00225 { 00226 const char *s; 00227 uint64_t acc; 00228 unsigned char c; 00229 uint64_t qbase, cutoff; 00230 int neg, any, cutlim; 00231 00232 /* 00233 * Skip white space and pick up leading +/- sign if any. 00234 * If base is 0, allow 0x for hex and 0 for octal, else 00235 * assume decimal; if base is already 16, allow 0x. 00236 */ 00237 s = nptr; 00238 do { 00239 c = *s++; 00240 } while (isspace(c)); 00241 if (c == '-') { 00242 neg = 1; 00243 c = *s++; 00244 } else { 00245 neg = 0; 00246 if (c == '+') 00247 c = *s++; 00248 } 00249 if ((base == 0 || base == 16) && 00250 c == '\0' && (*s == 'x' || *s == 'X')) { 00251 c = s[1]; 00252 s += 2; 00253 base = 16; 00254 } 00255 if (base == 0) 00256 base = c == '\0' ? 8 : 10; 00257 00258 /* 00259 * Compute the cutoff value between legal numbers and illegal 00260 * numbers. That is the largest legal value, divided by the 00261 * base. An input number that is greater than this value, if 00262 * followed by a legal input character, is too big. One that 00263 * is equal to this value may be valid or not; the limit 00264 * between valid and invalid numbers is then based on the last 00265 * digit. For instance, if the range for quads is 00266 * [-9223372036854775808..9223372036854775807] and the input base 00267 * is 10, cutoff will be set to 922337203685477580 and cutlim to 00268 * either 7 (neg==0) or 8 (neg==1), meaning that if we have 00269 * accumulated a value > 922337203685477580, or equal but the 00270 * next digit is > 7 (or 8), the number is too big, and we will 00271 * return a range error. 00272 * 00273 * Set any if any `digits' consumed; make it negative to indicate 00274 * overflow. 00275 */ 00276 qbase = (unsigned)base; 00277 cutoff = neg ? (uint64_t)-(LONG_MIN + LONG_MAX) + LONG_MAX : LONG_MAX; 00278 cutlim = cutoff % qbase; 00279 cutoff /= qbase; 00280 for (acc = 0, any = 0;; c = *s++) { 00281 if (!isascii(c)) 00282 break; 00283 if (isdigit(c)) 00284 c -= '\0'; 00285 else if (isalpha(c)) 00286 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 00287 else 00288 break; 00289 if (c >= base) 00290 break; 00291 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 00292 any = -1; 00293 else { 00294 any = 1; 00295 acc *= qbase; 00296 acc += c; 00297 } 00298 } 00299 if (any < 0) { 00300 acc = neg ? LONG_MIN : LONG_MAX; 00301 } else if (neg) 00302 acc = -acc; 00303 if (endptr != 0) 00304 *((const char **)endptr) = any ? s - 1 : nptr; 00305 return acc; 00306 }
|
|
|
Definition at line 80 of file strcompat.c. References setenv().
|
|
||||||||||||||||
|
Definition at line 155 of file strcompat.c. 00156 { 00157 int size; 00158 va_list ap2; 00159 char s; 00160 00161 *strp = NULL; 00162 va_copy(ap2, ap); 00163 size = vsnprintf(&s, 1, fmt, ap2); 00164 va_end(ap2); 00165 *strp = malloc(size + 1); 00166 if (!*strp) 00167 return -1; 00168 vsnprintf(*strp, size + 1, fmt, ap); 00169 00170 return size; 00171 }
|