Compatibility functions for strsep and strtoq missing on Solaris. More...
#include "asterisk.h"#include <ctype.h>
Go to the source code of this file.
Defines | |
| #define | LONG_MAX 9223372036854775807L |
| #define | LONG_MIN (-9223372036854775807L-1L) |
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 *haystack, const char *needle) |
| 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 *s, size_t n) |
| size_t | strnlen (const char *s, size_t n) |
| 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) |
| static char * | upper (const char *orig, char *buf, int bufsize) |
| int | vasprintf (char **strp, const char *fmt, va_list ap) |
Compatibility functions for strsep and strtoq missing on Solaris.
Definition in file agi/strcompat.c.
| #define LONG_MAX 9223372036854775807L |
Definition at line 219 of file agi/strcompat.c.
Referenced by process_sdp_a_audio(), and strtoq().
| #define LONG_MIN (-9223372036854775807L-1L) |
Definition at line 215 of file agi/strcompat.c.
Referenced by process_sdp_a_audio(), and strtoq().
| int asprintf | ( | char ** | str, |
| const char * | fmt, | ||
| ... | |||
| ) |
Definition at line 199 of file agi/strcompat.c.
| 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 agi/strcompat.c.
Referenced by ast_readconfig(), cli_prompt(), increase_call_count(), and sysinfo_helper().
{
int i;
for (i = 0; i < nelem; i++) {
list[i] = 0.1;
}
return -1;
}
| int setenv | ( | const char * | name, |
| const char * | value, | ||
| int | overwrite | ||
| ) |
Definition at line 54 of file agi/strcompat.c.
Referenced by env_write(), launch_script(), load_odbc_config(), read_environment(), and unsetenv().
| char* strcasestr | ( | const char * | haystack, |
| const char * | needle | ||
| ) |
Definition at line 93 of file agi/strcompat.c.
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().
{
char *u1, *u2;
int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
u1 = alloca(u1len);
u2 = alloca(u2len);
if (u1 && u2) {
char *offset;
if (u2len > u1len) {
/* Needle bigger than haystack */
return NULL;
}
offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len));
if (offset) {
/* Return the offset into the original string */
return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1)));
} else {
return NULL;
}
} else {
return NULL;
}
}
| size_t strlcat | ( | char * | dst, |
| const char * | src, | ||
| size_t | siz | ||
| ) |
Definition at line 388 of file agi/strcompat.c.
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return dlen + strlen(s);
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return dlen + (s - src); /* count does not include NUL */
}
| size_t strlcpy | ( | char * | dst, |
| const char * | src, | ||
| size_t | siz | ||
| ) |
Definition at line 452 of file agi/strcompat.c.
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return s - src - 1; /* count does not include NUL */
}
| char* strndup | ( | const char * | s, |
| size_t | n | ||
| ) |
| size_t strnlen | ( | const char * | s, |
| size_t | n | ||
| ) |
| char* strsep | ( | char ** | str, |
| const char * | delims | ||
| ) |
Definition at line 27 of file agi/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(), 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().
| uint64_t strtoq | ( | const char * | nptr, |
| char ** | endptr, | ||
| int | base | ||
| ) |
Convert a string to a quad integer.
Definition at line 229 of file agi/strcompat.c.
{
const char *s;
uint64_t acc;
unsigned char c;
uint64_t qbase, cutoff;
int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
do {
c = *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else {
neg = 0;
if (c == '+')
c = *s++;
}
if ((base == 0 || base == 16) &&
c == '\0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '\0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for quads is
* [-9223372036854775808..9223372036854775807] and the input base
* is 10, cutoff will be set to 922337203685477580 and cutlim to
* either 7 (neg==0) or 8 (neg==1), meaning that if we have
* accumulated a value > 922337203685477580, or equal but the
* next digit is > 7 (or 8), the number is too big, and we will
* return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
qbase = (unsigned)base;
cutoff = neg ? (uint64_t)-(LONG_MIN + LONG_MAX) + LONG_MAX : LONG_MAX;
cutlim = cutoff % qbase;
cutoff /= qbase;
for (acc = 0, any = 0;; c = *s++) {
if (!isascii(c))
break;
if (isdigit(c))
c -= '\0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= qbase;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
} else if (neg)
acc = -acc;
if (endptr != 0)
*((const char **)endptr) = any ? s - 1 : nptr;
return acc;
}
| void timersub | ( | struct timeval * | tvend, |
| struct timeval * | tvstart, | ||
| struct timeval * | tvdiff | ||
| ) |
Definition at line 167 of file agi/strcompat.c.
Referenced by ast_rtcp_write_rr(), ast_rtcp_write_sr(), and ast_select().
{
tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
if (tvdiff->tv_usec < 0) {
tvdiff->tv_sec --;
tvdiff->tv_usec += 1000000;
}
}
| int unsetenv | ( | const char * | name | ) |
Definition at line 72 of file agi/strcompat.c.
Referenced by env_write().
| static char* upper | ( | const char * | orig, |
| char * | buf, | ||
| int | bufsize | ||
| ) | [static] |
| int vasprintf | ( | char ** | strp, |
| const char * | fmt, | ||
| va_list | ap | ||
| ) |
Definition at line 147 of file agi/strcompat.c.