#include "asterisk/compiler.h"
#include <stdarg.h>
#include <stdio.h>
#include <sys/poll.h>
#include <errno.h>
#include <glob.h>


Go to the source code of this file.
Defines | |
| #define | __STDC_VERSION__ 0 |
| #define | MY_GLOB_FLAGS (GLOB_NOMAGIC|GLOB_BRACE) |
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 *) |
| size_t | strlcat (char *dst, const char *src, size_t siz) |
| size_t | strlcpy (char *dst, const char *src, size_t siz) |
| 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. | |
| void | timersub (struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff) |
| int | unsetenv (const char *name) |
| int | vasprintf (char **strp, const char *fmt, va_list ap) |
Definition in file compat.h.
| #define MY_GLOB_FLAGS (GLOB_NOMAGIC|GLOB_BRACE) |
| 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.
Definition at line 338 of file strcompat.c.
Referenced by ast_readconfig(), cli_prompt(), increase_call_count(), and sysinfo_helper().
00339 { 00340 int i; 00341 00342 for (i = 0; i < nelem; i++) { 00343 list[i] = 0.1; 00344 } 00345 return -1; 00346 }
| int setenv | ( | const char * | name, | |
| const char * | value, | |||
| int | overwrite | |||
| ) |
Definition at line 54 of file strcompat.c.
References buf.
Referenced by env_write(), launch_script(), load_odbc_config(), read_environment(), and unsetenv().
00055 { 00056 unsigned char *buf; 00057 int buflen; 00058 00059 buflen = strlen(name) + strlen(value) + 2; 00060 buf = alloca(buflen); 00061 00062 if (!overwrite && getenv(name)) 00063 return 0; 00064 00065 snprintf(buf, buflen, "%s=%s", name, value); 00066 00067 return putenv(buf); 00068 }
| char* strcasestr | ( | const char * | , | |
| const char * | ||||
| ) |
Definition at line 93 of file strcompat.c.
References upper().
Referenced by action_originate(), anti_injection(), common_exec(), find_sdp(), find_table_cb(), get_rdnis(), get_refer_info(), gettag(), handle_request_invite(), handle_response_register(), handle_show_applications(), modlist_modentry(), parse_moved_contact(), parse_register_contact(), playback_exec(), process_dahdi(), realtime_multi_odbc(), realtime_odbc(), register_verify(), reqprep(), respprep(), search_directory_sub(), sip_sipredirect(), sip_uri_headers_cmp(), and word_match().
00094 { 00095 char *u1, *u2; 00096 int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1; 00097 00098 u1 = alloca(u1len); 00099 u2 = alloca(u2len); 00100 if (u1 && u2) { 00101 char *offset; 00102 if (u2len > u1len) { 00103 /* Needle bigger than haystack */ 00104 return NULL; 00105 } 00106 offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len)); 00107 if (offset) { 00108 /* Return the offset into the original string */ 00109 return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1))); 00110 } else { 00111 return NULL; 00112 } 00113 } else { 00114 return NULL; 00115 } 00116 }
| size_t strlcat | ( | char * | dst, | |
| const char * | src, | |||
| size_t | siz | |||
| ) |
Definition at line 388 of file strcompat.c.
References s.
00389 { 00390 register char *d = dst; 00391 register const char *s = src; 00392 register size_t n = siz; 00393 size_t dlen; 00394 00395 /* Find the end of dst and adjust bytes left but don't go past end */ 00396 while (n-- != 0 && *d != '\0') 00397 d++; 00398 dlen = d - dst; 00399 n = siz - dlen; 00400 00401 if (n == 0) 00402 return dlen + strlen(s); 00403 00404 while (*s != '\0') { 00405 if (n != 1) { 00406 *d++ = *s; 00407 n--; 00408 } 00409 s++; 00410 } 00411 *d = '\0'; 00412 00413 return dlen + (s - src); /* count does not include NUL */ 00414 }
| size_t strlcpy | ( | char * | dst, | |
| const char * | src, | |||
| size_t | siz | |||
| ) |
Definition at line 452 of file strcompat.c.
References s.
00453 { 00454 register char *d = dst; 00455 register const char *s = src; 00456 register size_t n = siz; 00457 00458 /* Copy as many bytes as will fit */ 00459 if (n != 0 && --n != 0) { 00460 do { 00461 if ((*d++ = *s++) == 0) 00462 break; 00463 } while (--n != 0); 00464 } 00465 00466 /* Not enough room in dst, add NUL and traverse rest of src */ 00467 if (n == 0) { 00468 if (siz != 0) 00469 *d = '\0'; /* NUL-terminate dst */ 00470 while (*s++) 00471 ; 00472 } 00473 00474 return s - src - 1; /* count does not include NUL */ 00475 }
| char* strndup | ( | const char * | , | |
| size_t | ||||
| ) |
| size_t strnlen | ( | const char * | , | |
| size_t | ||||
| ) |
| char* strsep | ( | char ** | str, | |
| const char * | delims | |||
| ) |
Definition at line 27 of file strcompat.c.
Referenced by __ast_play_and_record(), _ast_device_state(), _build_port_config(), _macro_exec(), _parse(), acf_curl_exec(), acf_vmcount_exec(), add_peer_mailboxes(), add_redirect(), adsi_load(), adsi_message(), append_history_va(), append_mailbox(), append_mailbox_mapping(), apply_options(), apply_outgoing(), ast_aji_get_client(), ast_app_getdata(), ast_build_timing(), ast_eivr_getvariable(), ast_eivr_setvariable(), ast_el_strtoarr(), ast_extension_state2(), ast_filehelper(), ast_format_str_reduce(), ast_get_group(), ast_netsock_bind(), ast_parse_allow_disallow(), ast_parse_arg(), ast_playtones_start(), ast_read_image(), ast_remotecontrol(), ast_utils_which(), astman_get_variables(), attempt_reconnect(), auth_exec(), authenticate_verify(), build_channels(), build_gateway(), build_peer(), builtin_atxfer(), callerid_read(), check_auth(), check_blacklist(), check_user_full(), check_via_response(), cleanup_stale_contexts(), collect_function_digits(), common_exec(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_meetmecmd(), conf_exec(), conf_run(), config_curl(), config_line(), config_parse_variables(), connect_link(), console_dial(), cut_internal(), dahdi_request(), decrypt_frame(), del_exec(), deltree_exec(), dial_exec_full(), dial_trunk(), do_say(), do_timelimit(), exec_exec(), exts_compare(), extstate_read(), feature_interpret_helper(), fileexists_core(), find_gtalk(), forward_message(), function_fieldqty(), function_ilink(), function_remote(), function_sippeer(), get_destination(), get_range(), get_rdnis(), get_timerange(), gettag(), gosub_exec(), gtalk_alloc(), gtalk_request(), handle_cli_dialplan_add_extension(), handle_common_options(), handle_debug_dialplan(), handle_request_invite(), handle_request_notify(), handle_show_dialplan(), handle_statechange(), handle_t38_options(), handle_uri(), has_voicemail(), hint_read(), httpd_helper_thread(), iax2_register(), iftime(), inboxcount2(), is_prefix(), ivr_dispatch(), jingle_request(), leave_voicemail(), load_column_config(), load_config(), make_components(), metermaidstate(), misdn_request(), misdn_set_opt_exec(), mkintf(), notify_message(), notify_new_message(), orig_app(), orig_exten(), originate_exec(), page_exec(), parkandannounce_exec(), parse_cookies(), parse_dial_string(), parse_empty_options(), parse_register_contact(), parse_session_expires(), parse_uri(), parse_via(), pbx_builtin_background(), pbx_builtin_execiftime(), pbx_builtin_gotoif(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_saynumber(), pbx_builtin_setvar(), pbx_find_extension(), pbx_load_config(), pbx_load_users(), pbx_parseable_goto(), peer_set_srcaddr(), pickup_exec(), pickupchan_exec(), playback_exec(), process_dahdi(), process_sdp_o(), process_text_line(), queue_mwi_event(), queue_set_param(), read_config_maps(), readfile_exec(), realtime_curl(), realtime_multi_curl(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), reg_source_db(), register_exten(), register_peer_exten(), register_verify(), reload_agents(), reload_config(), reload_queue_members(), reply_digest(), rpt_exec(), rpt_tele_thread(), search_directory_sub(), send_tone_telemetry(), sendmail(), set(), set_config_flags(), set_insecure_flags(), sip_do_debug_ip(), sip_sipredirect(), sip_uri_cmp(), sip_uri_headers_cmp(), sip_uri_params_cmp(), sla_add_trunk_to_station(), sla_check_device(), sla_queue_event_conf(), sla_ring_station(), sla_state(), sla_station_exec(), sort_internal(), spawn_mp3(), spawn_ras(), speech_background(), ss_thread(), stat_read(), store_tone_zone_ring_cadence(), timezone_add(), transmit_fake_auth_response(), transmit_state_notify(), tryexec_exec(), unistim_send_mwi_to_peer(), unregister_exten(), update_registry(), vmauthenticate(), write_htmldump(), and xml_translate().
00028 { 00029 char *token; 00030 00031 if (!*str) { 00032 /* No more tokens */ 00033 return NULL; 00034 } 00035 00036 token = *str; 00037 while (**str != '\0') { 00038 if (strchr(delims, **str)) { 00039 **str = '\0'; 00040 (*str)++; 00041 return token; 00042 } 00043 (*str)++; 00044 } 00045 00046 /* There is no other token */ 00047 *str = NULL; 00048 00049 return token; 00050 }
| uint64_t strtoq | ( | const char * | nptr, | |
| char ** | endptr, | |||
| int | base | |||
| ) |
Convert a string to a quad integer.
Definition at line 229 of file strcompat.c.
References LONG_MAX, LONG_MIN, and s.
00230 { 00231 const char *s; 00232 uint64_t acc; 00233 unsigned char c; 00234 uint64_t qbase, cutoff; 00235 int neg, any, cutlim; 00236 00237 /* 00238 * Skip white space and pick up leading +/- sign if any. 00239 * If base is 0, allow 0x for hex and 0 for octal, else 00240 * assume decimal; if base is already 16, allow 0x. 00241 */ 00242 s = nptr; 00243 do { 00244 c = *s++; 00245 } while (isspace(c)); 00246 if (c == '-') { 00247 neg = 1; 00248 c = *s++; 00249 } else { 00250 neg = 0; 00251 if (c == '+') 00252 c = *s++; 00253 } 00254 if ((base == 0 || base == 16) && 00255 c == '\0' && (*s == 'x' || *s == 'X')) { 00256 c = s[1]; 00257 s += 2; 00258 base = 16; 00259 } 00260 if (base == 0) 00261 base = c == '\0' ? 8 : 10; 00262 00263 /* 00264 * Compute the cutoff value between legal numbers and illegal 00265 * numbers. That is the largest legal value, divided by the 00266 * base. An input number that is greater than this value, if 00267 * followed by a legal input character, is too big. One that 00268 * is equal to this value may be valid or not; the limit 00269 * between valid and invalid numbers is then based on the last 00270 * digit. For instance, if the range for quads is 00271 * [-9223372036854775808..9223372036854775807] and the input base 00272 * is 10, cutoff will be set to 922337203685477580 and cutlim to 00273 * either 7 (neg==0) or 8 (neg==1), meaning that if we have 00274 * accumulated a value > 922337203685477580, or equal but the 00275 * next digit is > 7 (or 8), the number is too big, and we will 00276 * return a range error. 00277 * 00278 * Set any if any `digits' consumed; make it negative to indicate 00279 * overflow. 00280 */ 00281 qbase = (unsigned)base; 00282 cutoff = neg ? (uint64_t)-(LONG_MIN + LONG_MAX) + LONG_MAX : LONG_MAX; 00283 cutlim = cutoff % qbase; 00284 cutoff /= qbase; 00285 for (acc = 0, any = 0;; c = *s++) { 00286 if (!isascii(c)) 00287 break; 00288 if (isdigit(c)) 00289 c -= '\0'; 00290 else if (isalpha(c)) 00291 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 00292 else 00293 break; 00294 if (c >= base) 00295 break; 00296 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 00297 any = -1; 00298 else { 00299 any = 1; 00300 acc *= qbase; 00301 acc += c; 00302 } 00303 } 00304 if (any < 0) { 00305 acc = neg ? LONG_MIN : LONG_MAX; 00306 } else if (neg) 00307 acc = -acc; 00308 if (endptr != 0) 00309 *((const char **)endptr) = any ? s - 1 : nptr; 00310 return acc; 00311 }
| void timersub | ( | struct timeval * | tvend, | |
| struct timeval * | tvstart, | |||
| struct timeval * | tvdiff | |||
| ) |
Definition at line 167 of file strcompat.c.
Referenced by ast_rtcp_write_rr(), ast_rtcp_write_sr(), and ast_select().
00168 { 00169 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec; 00170 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec; 00171 if (tvdiff->tv_usec < 0) { 00172 tvdiff->tv_sec --; 00173 tvdiff->tv_usec += 1000000; 00174 } 00175 00176 }
| int unsetenv | ( | const char * | name | ) |
| int vasprintf | ( | char ** | strp, | |
| const char * | fmt, | |||
| va_list | ap | |||
| ) |
Definition at line 147 of file strcompat.c.
00148 { 00149 int size; 00150 va_list ap2; 00151 char s; 00152 00153 *strp = NULL; 00154 va_copy(ap2, ap); 00155 size = vsnprintf(&s, 1, fmt, ap2); 00156 va_end(ap2); 00157 *strp = malloc(size + 1); 00158 if (!*strp) 00159 return -1; 00160 vsnprintf(*strp, size + 1, fmt, ap); 00161 00162 return size; 00163 }
1.5.6