#include "asterisk/compiler.h"
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdlib.h>
#include <alloca.h>
#include <stdio.h>
#include <string.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 | LLONG_MAX 9223372036854775807LL |
#define | MY_GLOB_FLAGS GLOB_NOCHECK |
#define | strlcat __use__ast_str__functions_not__strlcat__ |
#define | strlcpy __use__ast_copy_string__not__strlcpy__ |
Functions | |
int | asprintf (char **str, const char *fmt,...) |
void | closefrom (int lowfd) |
int | ffsll (long long n) |
int | getloadavg (double *list, int nelem) |
uint64_t | htonll (uint64_t host64) |
char * | mkdtemp (char *template_s) |
uint64_t | ntohll (uint64_t net64) |
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) |
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 LLONG_MAX 9223372036854775807LL |
#define MY_GLOB_FLAGS GLOB_NOCHECK |
int asprintf | ( | char ** | str, | |
const char * | fmt, | |||
... | ||||
) |
void closefrom | ( | int | lowfd | ) |
Definition at line 428 of file strcompat.c.
References errno.
Referenced by ast_close_fds_above_n().
00429 { 00430 long x; 00431 struct rlimit rl; 00432 DIR *dir; 00433 char path[16], *result; 00434 struct dirent *entry; 00435 00436 snprintf(path, sizeof(path), "/proc/%d/fd", (int) getpid()); 00437 if ((dir = opendir(path))) { 00438 while ((entry = readdir(dir))) { 00439 /* Skip . and .. */ 00440 if (entry->d_name[0] == '.') { 00441 continue; 00442 } 00443 if ((x = strtol(entry->d_name, &result, 10)) && x >= n) { 00444 #ifdef STRICT_COMPAT 00445 close(x); 00446 #else 00447 /* This isn't strictly compatible, but it's actually faster 00448 * for our purposes to set the CLOEXEC flag than to close 00449 * file descriptors. 00450 */ 00451 long flags = fcntl(x, F_GETFD); 00452 if (flags == -1 && errno == EBADF) { 00453 continue; 00454 } 00455 fcntl(x, F_SETFD, flags | FD_CLOEXEC); 00456 #endif 00457 } 00458 } 00459 closedir(dir); 00460 } else { 00461 getrlimit(RLIMIT_NOFILE, &rl); 00462 if (rl.rlim_cur > 65535) { 00463 /* A more reasonable value. Consider that the primary source of 00464 * file descriptors in Asterisk are UDP sockets, of which we are 00465 * limited to 65,535 per address. We additionally limit that down 00466 * to about 10,000 sockets per protocol. While the kernel will 00467 * allow us to set the fileno limit higher (up to 4.2 billion), 00468 * there really is no practical reason for it to be that high. 00469 */ 00470 rl.rlim_cur = 65535; 00471 } 00472 for (x = n; x < rl.rlim_cur; x++) { 00473 #ifdef STRICT_COMPAT 00474 close(x); 00475 #else 00476 long flags = fcntl(x, F_GETFD); 00477 if (flags == -1 && errno == EBADF) { 00478 continue; 00479 } 00480 fcntl(x, F_SETFD, flags | FD_CLOEXEC); 00481 #endif 00482 } 00483 } 00484 }
int ffsll | ( | long long | n | ) |
Referenced by powerof().
int getloadavg | ( | double * | list, | |
int | nelem | |||
) |
Referenced by cli_prompt(), increase_call_count(), and sysinfo_helper().
uint64_t htonll | ( | uint64_t | host64 | ) |
Definition at line 389 of file strcompat.c.
Referenced by iax_ie_append_versioned_uint64().
00390 { 00391 #if BYTE_ORDER == BIG_ENDIAN 00392 return host64; 00393 #elif BYTE_ORDER == LITTLE_ENDIAN 00394 union { 00395 unsigned char c[8]; 00396 uint64_t u; 00397 } number; 00398 number.u = host64; 00399 return 00400 (((uint64_t) number.c[0]) << 56) | 00401 (((uint64_t) number.c[1]) << 48) | 00402 (((uint64_t) number.c[2]) << 40) | 00403 (((uint64_t) number.c[3]) << 32) | 00404 (((uint64_t) number.c[4]) << 24) | 00405 (((uint64_t) number.c[5]) << 16) | 00406 (((uint64_t) number.c[6]) << 8) | 00407 (((uint64_t) number.c[7]) << 0); 00408 #else 00409 #error "Unknown byte order" 00410 #endif 00411 }
char* mkdtemp | ( | char * | template_s | ) |
uint64_t ntohll | ( | uint64_t | net64 | ) |
Definition at line 363 of file strcompat.c.
Referenced by dump_versioned_codec(), and iax_parse_ies().
00364 { 00365 #if BYTE_ORDER == BIG_ENDIAN 00366 return net64; 00367 #elif BYTE_ORDER == LITTLE_ENDIAN 00368 union { 00369 unsigned char c[8]; 00370 uint64_t u; 00371 } number; 00372 number.u = net64; 00373 return 00374 (((uint64_t) number.c[0]) << 56) | 00375 (((uint64_t) number.c[1]) << 48) | 00376 (((uint64_t) number.c[2]) << 40) | 00377 (((uint64_t) number.c[3]) << 32) | 00378 (((uint64_t) number.c[4]) << 24) | 00379 (((uint64_t) number.c[5]) << 16) | 00380 (((uint64_t) number.c[6]) << 8) | 00381 (((uint64_t) number.c[7]) << 0); 00382 #else 00383 #error "Unknown byte order" 00384 #endif 00385 }
int setenv | ( | const char * | name, | |
const char * | value, | |||
int | overwrite | |||
) |
Referenced by env_init(), env_write(), launch_script(), load_odbc_config(), and read_environment().
char* strcasestr | ( | const char * | , | |
const char * | ||||
) |
Referenced by action_originate(), anti_injection(), ast_xmldoc_printable(), common_exec(), find_sdp(), find_table_cb(), frame_trace_helper(), 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(), realtime_multi_odbc(), realtime_odbc(), register_verify(), reqprep(), respprep(), search_directory_sub(), sip_sipredirect(), sip_uri_headers_cmp(), and word_match().
char* strndup | ( | const char * | , | |
size_t | ||||
) |
size_t strnlen | ( | const char * | , | |
size_t | ||||
) |
char* strsep | ( | char ** | str, | |
const char * | delims | |||
) |
Referenced by __analog_ss_thread(), __ast_play_and_record(), _ast_device_state(), _build_port_config(), _macro_exec(), _parse(), acf_curl_helper(), acf_vmcount_exec(), actual_load_config(), add_peer_mailboxes(), add_redirect(), adsi_message(), aji_handle_pubsub_event(), analog_ss_thread(), append_history_va(), append_mailbox(), append_mailbox_mapping(), apply_options(), apply_outgoing(), ast_aji_get_client(), ast_app_getdata(), ast_append_ha(), ast_bridge_timelimit(), ast_build_timing(), ast_eivr_getvariable(), ast_eivr_setvariable(), ast_el_strtoarr(), ast_extension_state3(), ast_filehelper(), ast_format_str_reduce(), ast_get_group(), ast_netsock_bind(), ast_parse_allow_disallow(), ast_parse_arg(), ast_parse_digest(), ast_playtones_start(), ast_read_image(), ast_remotecontrol(), ast_utils_which(), authenticate_verify(), build_channels(), build_peer(), build_route(), builtin_atxfer(), check_auth(), check_blacklist(), check_user_full(), check_via_response(), cleanup_stale_contexts(), 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(), console_dial(), create_queue_member(), cut_internal(), data_filter_alloc(), decrypt_frame(), del_exec(), deltree_exec(), dial_exec_full(), dial_trunk(), ewscal_write_event(), exec_exec(), exts_compare(), extstate_read(), feature_interpret_helper(), find_gtalk(), forward_message(), function_fieldnum_helper(), function_fieldqty_helper(), function_sippeer(), 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(), load_channelvars(), load_column_config(), load_dynamic_module(), make_components(), man_do_variable_value(), mark_parsed_methods(), metermaidstate(), misdn_set_opt_exec(), next_node_name(), notify_message(), notify_new_message(), orig_app(), orig_exten(), originate_exec(), parkandannounce_exec(), parse_apps(), parse_cookies(), parse_dial_string(), parse_empty_options(), parse_events(), parse_register_contact(), parse_session_expires(), parse_uri_full(), 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_users(), pbx_parseable_goto(), peer_set_srcaddr(), pickup_exec(), pickupchan_exec(), playback_exec(), process_applicationmap_line(), 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(), register_exten(), register_peer_exten(), register_verify(), reload_queue_members(), reply_digest(), sdp_crypto_process(), search_directory_sub(), sendfax_exec(), sendmail(), set(), set_config_flags(), set_insecure_flags(), sig_pri_start_pri(), sip_get_cc_information(), 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(), stat_read(), state_notify_build_xml(), store_tone_zone_ring_cadence(), timezone_add(), transmit_fake_auth_response(), tryexec_exec(), unistim_send_mwi_to_peer(), unregister_exten(), update_registry(), vmauthenticate(), and write_htmldump().
uint64_t strtoq | ( | const char * | nptr, | |
char ** | endptr, | |||
int | base | |||
) |
void timersub | ( | struct timeval * | tvend, | |
struct timeval * | tvstart, | |||
struct timeval * | tvdiff | |||
) |
Referenced by ast_rtcp_write_rr(), ast_rtcp_write_sr(), and ast_select().
int unsetenv | ( | const char * | name | ) |
Referenced by env_write().
int vasprintf | ( | char ** | strp, | |
const char * | fmt, | |||
va_list | ap | |||
) |