Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:28 2007

Asterisk developer's documentation :: Codename Pineapple


compat.h File Reference


Detailed Description

General Definitions for Asterisk top level program.

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)


Function Documentation

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

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 }

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 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 }

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

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 }

char* strcasestr const char *  ,
const char * 
 

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 }

char* strndup const char *  ,
size_t 
 

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 }

size_t strnlen const char *  ,
size_t 
 

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 }

char* strsep char **  str,
const char *  delims
 

Definition at line 35 of file strcompat.c.

Referenced by __ast_play_and_record(), __login_exec(), _build_port_config(), _parse(), add_realm_authentication(), add_redirect(), agi_exec_full(), aji_send_exec(), aji_status_exec(), append_history_va(), apply_outgoing(), ast_app_getdata(), ast_build_timing(), ast_device_state(), ast_el_strtoarr(), ast_extension_state2(), ast_filehelper(), ast_get_group(), ast_hint_state_changed(), ast_netsock_bind(), ast_parse_allow_disallow(), ast_parseable_goto(), ast_playtones_start(), ast_read_image(), ast_remotecontrol(), astman_get_variables(), authenticate_verify(), build_device(), check_auth(), check_user_full(), cleanup_stale_contexts(), complete_context_add_ignorepat(), complete_context_add_include(), complete_context_remove_include(), console_dial(), decrypt_frame(), extract_uri(), exts_compare(), find_gtalk(), fix_complete_args(), function_sippeer(), get_destination(), get_rdnis(), getSearchPath(), gettag(), gtalk_alloc(), gtalk_request(), handle_agidumphtml(), handle_common_options(), handle_context_add_extension(), handle_request_invite(), handle_request_subscribe(), handle_show_dialplan(), handle_uri(), httpd_helper_thread(), iax2_register(), ind_load_module(), is_prefix(), ivr_dispatch(), jingle_request(), make_components(), metermaidstate(), orig_app(), orig_exten(), parse_dial_string(), parse_moved_contact(), parse_register_contact(), parse_uri(), pbx_builtin_background(), pbx_builtin_execiftime(), pbx_builtin_gotoif(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_saynumber(), pbx_load_users(), peer_set_srcaddr(), process_text_line(), read_config_maps(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), reg_source_db(), register_peer_exten(), register_verify(), reload_agents(), reload_config(), reply_digest(), reqprep(), set_address_from_contact(), sip_do_debug_ip(), sip_sipredirect(), spawn_mp3(), split_ext(), ss_thread(), transmit_state_notify(), and zt_request().

00036 {
00037     char *token;
00038 
00039     if (!*str) {
00040         /* No more tokens */
00041         return NULL;
00042     }
00043 
00044     token = *str;
00045     while (**str != '\0') {
00046         if (strchr(delims, **str)) {
00047             **str = '\0';
00048             (*str)++;
00049             return token;
00050         }
00051         (*str)++;
00052     }
00053 
00054     /* There is no other token */
00055     *str = NULL;
00056 
00057     return token;
00058 }

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

Convert a string to a quad integer.

Note:
Ignores `locale' stuff. Assumes that the upper and lower case alphabets and digits are each contiguous.

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 }

int unsetenv const char *  name  ) 
 

Definition at line 80 of file strcompat.c.

References setenv().

00081 {
00082    return setenv(name, "", 0);
00083 }

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

Definition at line 155 of file strcompat.c.

References malloc, and s.

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 }


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen