Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
include/asterisk/compat.h File Reference

General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific issues especially those related to header files. More...

#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 <poll.h>
#include <errno.h>
#include <glob.h>
Include dependency graph for include/asterisk/compat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __STDC_VERSION__   0
 
#define INFINITY   (1.0/0.0)
 
#define LLONG_MAX   9223372036854775807LL
 
#define MY_GLOB_FLAGS   GLOB_NOCHECK
 
#define NAN   (0.0/0.0)
 
#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)
 
float roundf (float x)
 
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)
 

Detailed Description

General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific issues especially those related to header files.

Definition in file include/asterisk/compat.h.

Macro Definition Documentation

◆ __STDC_VERSION__

#define __STDC_VERSION__   0

Definition at line 27 of file include/asterisk/compat.h.

◆ INFINITY

#define INFINITY   (1.0/0.0)

Definition at line 210 of file include/asterisk/compat.h.

Referenced by cli_endpoint_print_body().

◆ LLONG_MAX

#define LLONG_MAX   9223372036854775807LL

Definition at line 60 of file include/asterisk/compat.h.

Referenced by AST_TEST_DEFINE(), file_read(), and file_write().

◆ MY_GLOB_FLAGS

#define MY_GLOB_FLAGS   GLOB_NOCHECK

◆ NAN

#define NAN   (0.0/0.0)

Definition at line 214 of file include/asterisk/compat.h.

Referenced by cli_contact_print_body().

◆ strlcat

#define strlcat   __use__ast_str__functions_not__strlcat__

Definition at line 127 of file include/asterisk/compat.h.

◆ strlcpy

#define strlcpy   __use__ast_copy_string__not__strlcpy__

Definition at line 128 of file include/asterisk/compat.h.

Function Documentation

◆ asprintf()

int asprintf ( char **  str,
const char *  fmt,
  ... 
)

Referenced by to_string(), and yyparse().

◆ closefrom()

void closefrom ( int  lowfd)
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 429 of file strcompat.c.

References ast_random(), errno, len(), mkdtemp(), NULL, POLL_SIZE, and roundf().

Referenced by ast_close_fds_above_n().

430 {
431  int maxfd;
432 #ifndef _SC_OPEN_MAX
433  struct rlimit rl;
434 #endif
435  struct pollfd fds[POLL_SIZE];
436  int fd=n, loopmax, i;
437 #ifndef STRICT_COMPAT
438  long flags;
439 #endif
440 
441 #ifndef _SC_OPEN_MAX
442  if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
443  maxfd = -1;
444  } else {
445  maxfd = rl.rlim_cur;
446  }
447 #else
448  maxfd = sysconf (_SC_OPEN_MAX);
449 #endif
450 
451  if (maxfd == -1 || maxfd > 65536) {
452  /* A more reasonable value. Consider that the primary source of
453  * file descriptors in Asterisk are UDP sockets, of which we are
454  * limited to 65,535 per address. We additionally limit that down
455  * to about 10,000 sockets per protocol. While the kernel will
456  * allow us to set the fileno limit higher (up to 4.2 billion),
457  * there really is no practical reason for it to be that high.
458  *
459  * sysconf as well as getrlimit can return -1 on error. Let's set
460  * maxfd to the mentioned reasonable value of 65,535 in this case.
461  */
462  maxfd = 65536;
463  }
464 
465  while (fd < maxfd) {
466  loopmax = maxfd - fd;
467  if (loopmax > POLL_SIZE) {
468  loopmax = POLL_SIZE;
469  }
470  for (i = 0; i < loopmax; i++) {
471  fds[i].fd = fd+i;
472  fds[i].events = 0;
473  }
474  poll(fds, loopmax, 0);
475  for (i = 0; i < loopmax; i++) {
476  if (fds[i].revents == POLLNVAL) {
477  continue;
478  }
479 #ifdef STRICT_COMPAT
480  close(fds[i].fd);
481 #else
482  /* This isn't strictly compatible, but it's actually faster
483  * for our purposes to set the CLOEXEC flag than to close
484  * file descriptors.
485  */
486  flags = fcntl(fds[i].fd, F_GETFD);
487  if (flags == -1 && errno == EBADF) {
488  continue;
489  }
490  fcntl(fds[i].fd, F_SETFD, flags | FD_CLOEXEC);
491 #endif
492  }
493  fd += loopmax;
494  }
495 }
#define POLL_SIZE
Definition: strcompat.c:41
int errno

◆ ffsll()

int ffsll ( long long  n)

Referenced by htonll().

◆ getloadavg()

int getloadavg ( double *  list,
int  nelem 
)

◆ htonll()

uint64_t htonll ( uint64_t  host64)

Definition at line 390 of file strcompat.c.

References c, and ffsll().

Referenced by ast_websocket_write(), and iax_ie_append_versioned_uint64().

391 {
392 #if BYTE_ORDER == BIG_ENDIAN
393  return host64;
394 #elif BYTE_ORDER == LITTLE_ENDIAN
395  union {
396  unsigned char c[8];
397  uint64_t u;
398  } number;
399  number.u = host64;
400  return
401  (((uint64_t) number.c[0]) << 56) |
402  (((uint64_t) number.c[1]) << 48) |
403  (((uint64_t) number.c[2]) << 40) |
404  (((uint64_t) number.c[3]) << 32) |
405  (((uint64_t) number.c[4]) << 24) |
406  (((uint64_t) number.c[5]) << 16) |
407  (((uint64_t) number.c[6]) << 8) |
408  (((uint64_t) number.c[7]) << 0);
409 #else
410  #error "Unknown byte order"
411 #endif
412 }
static struct test_val c
Number structure.
Definition: app_followme.c:154

◆ mkdtemp()

char* mkdtemp ( char *  template_s)

◆ ntohll()

uint64_t ntohll ( uint64_t  net64)

Definition at line 364 of file strcompat.c.

References c.

Referenced by ast_websocket_read(), dump_versioned_codec(), and iax_parse_ies().

365 {
366 #if BYTE_ORDER == BIG_ENDIAN
367  return net64;
368 #elif BYTE_ORDER == LITTLE_ENDIAN
369  union {
370  unsigned char c[8];
371  uint64_t u;
372  } number;
373  number.u = net64;
374  return
375  (((uint64_t) number.c[0]) << 56) |
376  (((uint64_t) number.c[1]) << 48) |
377  (((uint64_t) number.c[2]) << 40) |
378  (((uint64_t) number.c[3]) << 32) |
379  (((uint64_t) number.c[4]) << 24) |
380  (((uint64_t) number.c[5]) << 16) |
381  (((uint64_t) number.c[6]) << 8) |
382  (((uint64_t) number.c[7]) << 0);
383 #else
384  #error "Unknown byte order"
385 #endif
386 }
static struct test_val c
Number structure.
Definition: app_followme.c:154

◆ roundf()

float roundf ( float  x)

◆ setenv()

int setenv ( const char *  name,
const char *  value,
int  overwrite 
)

◆ strcasestr()

char* strcasestr ( const char *  ,
const char *   
)

◆ strndup()

char* strndup ( const char *  ,
size_t   
)

Referenced by __ast_repl_strndup().

◆ strnlen()

size_t strnlen ( const char *  ,
size_t   
)

◆ strsep()

char* strsep ( char **  str,
const char *  delims 
)
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Referenced by __analog_ss_thread(), __ast_play_and_record(), __ast_sorcery_apply_config(), _ast_device_state(), _build_port_config(), _macro_exec(), _parse(), acf_curl_helper(), action_command(), action_messagesend(), action_playback(), action_playback_and_continue(), actual_load_config(), add_hintdevice(), add_menu_entry(), add_peer_mailboxes(), add_redirect(), adsi_load(), adsi_message(), ami_sip_qualify(), aMYSQL_clear(), aMYSQL_disconnect(), aMYSQL_fetch(), analog_ss_thread(), announce_to_dial(), append_ha_core(), append_history_va(), append_mailbox(), append_mailbox_mapping(), apply_options(), apps_handler(), ari_channels_handle_originate_with_id(), ast_app_getdata(), ast_append_acl(), ast_ari_channels_create(), ast_ari_invoke(), ast_bridge_timelimit(), ast_build_timing(), ast_dns_test_write_domain(), ast_eivr_getvariable(), ast_eivr_setvariable(), ast_el_strtoarr(), ast_extension_state3(), ast_format_cap_update_by_allow_disallow(), ast_format_str_reduce(), ast_get_chan_applicationmap(), ast_get_group(), ast_get_namedgroups(), ast_http_get_auth(), ast_http_get_post_vars(), ast_http_header_parse(), ast_msg_send(), ast_parse_arg(), ast_parse_digest(), ast_playtones_start(), ast_presence_state_helper(), ast_read_image(), ast_remotecontrol(), ast_say_number_full_en(), ast_sip_auth_vector_init(), ast_sip_for_each_aor(), ast_sip_location_retrieve_contact_and_aor_from_list_filtered(), ast_sip_validate_uri_length(), ast_strings_match(), ast_utils_which(), ast_vector_string_split(), ast_websocket_uri_cb(), asterisk_publication_mailboxstate(), auth_exec(), authenticate_api_key(), authenticate_verify(), bridge_create_common(), build_calendar(), build_channels(), build_peer(), build_user(), chanavail_exec(), check_blacklist(), check_nonce(), check_user_full(), cleanup_stale_contexts(), cli_qualify(), cli_reload_qualify_endpoint(), cli_show_qualify_endpoint(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), conf_exec(), conf_run(), config_curl(), config_parse_variables(), console_dial(), create_queue_member(), create_unsolicited_mwi_subscriptions(), cut_internal(), decrypt_frame(), deltree_exec(), dial_exec_full(), dial_trunk(), do_say(), dtmf_info_incoming_request(), eval_exten_read(), events_handler(), ewscal_write_event(), exec_exec(), expand_gosub_args(), extstate_read(), filehelper(), find_aor(), find_aor_for_resource(), find_aor_name(), find_body_generator_accept(), forward_message(), free_zone(), freq_parser(), function_fieldnum_helper(), function_fieldqty_helper(), function_ooh323_write(), function_sippeer(), get_mid_bundle_group(), get_range(), get_rdnis(), get_timerange(), gettag(), global_loaded(), gosub_exec(), goto_parser(), h263_parse_sdp_fmtp(), h264_parse_sdp_fmtp(), handle_cli_dialplan_add_extension(), handle_common_options(), handle_debug_dialplan(), handle_request_invite(), handle_request_notify(), handle_show_dialplan(), handle_t38_options(), handle_uri(), has_voicemail(), hint_read(), http_request_headers_get(), iax2_register(), ident_handler(), iftime(), inboxcount2(), init_logger_chain(), ip_identify_match_handler(), is_prefix(), ivr_dispatch(), jack_handler(), json_array_from_list(), leave_voicemail(), list_item_handler(), load_column_config(), load_values_config(), load_zonemessages(), make_components(), make_email_file(), man_do_variable_value(), manager_dialplan_extension_add(), manager_dialplan_extension_remove(), mark_parsed_methods(), metermaidstate(), misdn_set_opt_exec(), msg_send_exec(), mwi_contact_changed(), mwi_has_voicemail(), mwi_inboxcount(), mwi_on_aor(), mwi_to_event(), mwi_validate_for_aor(), notify_endpoint(), notify_new_message(), orig_app(), orig_exten(), origin_allowed(), originate_exec(), page_exec(), parse_cookies(), parse_data(), parse_dial_string(), parse_empty_options(), parse_line(), parse_register_contact(), parse_session_expires(), parse_tone_uri(), 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_config(), pbx_load_users(), pbx_parseable_goto(), permanent_uri_handler(), pickup_exec(), pickupchan_exec(), pjsip_acf_dial_contacts_read(), play_files_helper(), play_message(), playback_exec(), process_dahdi(), process_description_file(), process_echocancel(), process_sdp_o(), process_text_line(), publisher_start(), queue_set_param(), realtime_curl(), realtime_multi_curl(), realtime_multi_mysql(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_mysql(), realtime_odbc(), realtime_pgsql(), register_exten(), register_peer_exten(), register_verify(), reload_config(), reload_module(), reload_queue_members(), reply_digest(), res_sdp_crypto_parse_offer(), safe_scan_int(), say_character_str_full(), say_digit_str_full(), say_money_str_full(), say_phonetic_str_full(), search_directory_sub(), send_dial_tone(), send_unsolicited_mwi_notify(), sendfax_exec(), sendmail(), separate_mailbox(), set(), set_insecure_flags(), set_remote_mslabel_and_stream_group(), sip_digest_parser(), sip_get_cc_information(), sip_options_synchronize_endpoint(), sip_parse_nat_option(), sip_sendcustominfo(), sip_sipredirect(), sip_uri_cmp(), sip_uri_headers_cmp(), sip_uri_params_cmp(), skinny_call(), sla_add_trunk_to_station(), sla_check_device(), sla_queue_event_conf(), sla_ring_station(), sla_state(), sla_station_exec(), sorcery_config_open(), sorcery_memory_cache_open(), sorcery_realtime_open(), sort_internal(), spawn_mp3(), spawn_ras(), speech_background(), stat_read(), state_notify_build_xml(), store_tone_zone_ring_cadence(), test_cel_peer_strings_match(), timezone_add(), tls_method_to_str(), transmit_fake_auth_response(), tryexec_exec(), type_in_list(), unregister_exten(), user_event_hook_cb(), userevent_exec(), vm_allocate_dh(), vmauthenticate(), write_htmldump(), xml_translate(), xmpp_client_authenticate_sasl(), xmpp_pubsub_handle_event(), and xmpp_send_cb().

◆ strtoq()

uint64_t strtoq ( const char *  nptr,
char **  endptr,
int  base 
)

◆ timersub()

void timersub ( struct timeval *  tvend,
struct timeval *  tvstart,
struct timeval *  tvdiff 
)

◆ unsetenv()

int unsetenv ( const char *  name)

Referenced by env_write(), and rxqcheck().

◆ vasprintf()

int vasprintf ( char **  strp,
const char *  fmt,
va_list  ap 
)