Back to index

glibc  2.9
Defines | Functions | Variables
stdlib.h File Reference
#include <stddef.h>
#include <stdlib/stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MB_CUR_MAX   (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX))
#define __cxa_atexit(func, arg, d)   INTUSE(__cxa_atexit) (func, arg, d)

Functions

__BEGIN_DECLS __typeof (strtol_l) __strtol_l
 __typeof (strtoul_l) __strtoul_l
 __typeof (strtoll_l) __strtoll_l
 __typeof (strtoull_l) __strtoull_l
 __typeof (strtod_l) __strtod_l
 __typeof (strtof_l) __strtof_l
 __typeof (strtold_l) __strtold_l
 libc_hidden_proto (__strtol_l) libc_hidden_proto(__strtoul_l) libc_hidden_proto(__strtoll_l) libc_hidden_proto(__strtoull_l) libc_hidden_proto(__strtod_l) libc_hidden_proto(__strtof_l) libc_hidden_proto(__strtold_l) libc_hidden_proto(exit) libc_hidden_proto(abort) libc_hidden_proto(getenv) libc_hidden_proto(bsearch) libc_hidden_proto(qsort) libc_hidden_proto(qsort_r) libc_hidden_proto(lrand48_r) libc_hidden_proto(wctomb) libc_hidden_proto(__secure_getenv) extern long int __random(void)
void __srandom (unsigned int __seed)
char * __initstate (unsigned int __seed, char *__statebuf, size_t __statelen)
char * __setstate (char *__statebuf)
int __random_r (struct random_data *__buf, int32_t *__result)
int __srandom_r (unsigned int __seed, struct random_data *__buf)
int __initstate_r (unsigned int __seed, char *__statebuf, size_t __statelen, struct random_data *__buf)
int __setstate_r (char *__statebuf, struct random_data *__buf)
int __rand_r (unsigned int *__seed)
int __erand48_r (unsigned short int __xsubi[3], struct drand48_data *__buffer, double *__result)
int __nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__buffer, long int *__result)
int __jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__buffer, long int *__result)
int __srand48_r (long int __seedval, struct drand48_data *__buffer)
int __seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer)
int __lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer)
int __drand48_iterate (unsigned short int __xsubi[3], struct drand48_data *__buffer)
int __setenv (__const char *__name, __const char *__value, int __replace)
int __unsetenv (__const char *__name)
int __clearenv (void)
char * __canonicalize_file_name (__const char *__name)
char * __realpath (__const char *__name, char *__resolved)
int __ptsname_r (int __fd, char *__buf, size_t __buflen)
int __getpt (void)
int __posix_openpt (int __oflag)
int __add_to_environ (const char *name, const char *value, const char *combines, int replace)
void _quicksort (void *const pbase, size_t total_elems, size_t size, __compar_d_fn_t cmp, void *arg)
int __on_exit (void(*__func)(int __status, void *__arg), void *__arg)
int __cxa_atexit (void(*func)(void *), void *arg, void *d)
int __cxa_atexit_internal (void(*func)(void *), void *arg, void *d) attribute_hidden
void __cxa_finalize (void *d)
int __posix_memalign (void **memptr, size_t alignment, size_t size)
void * __libc_memalign (size_t alignment, size_t size) __attribute_malloc__
int __libc_system (const char *line)
double __strtod_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __THROW __nonnull((1)) __wur
float __strtof_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __THROW __nonnull((1)) __wur
long double __strtold_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __THROW __nonnull((1)) __wur
long int __strtol_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __THROW __nonnull((1)) __wur
unsigned long int __strtoul_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __THROW __nonnull((1)) __wur
__extension__ long long int __strtoll_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __THROW __nonnull((1)) __wur
__extension__ unsigned long
long int 
__strtoull_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __THROW __nonnull((1)) __wur
 libc_hidden_proto (__strtof_internal) libc_hidden_proto(__strtod_internal) libc_hidden_proto(__strtold_internal) libc_hidden_proto(__strtol_internal) libc_hidden_proto(__strtoll_internal) libc_hidden_proto(__strtoul_internal) libc_hidden_proto(__strtoull_internal) extern double ____strtod_l_internal(__const char *__restrict __nptr
float ____strtof_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group, __locale_t __loc)
long double ____strtold_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group, __locale_t __loc)
long int ____strtol_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group, __locale_t __loc)
unsigned long int ____strtoul_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group, __locale_t __loc)
__extension__ long long int ____strtoll_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group, __locale_t __loc)
__extension__ unsigned long
long int 
____strtoull_l_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group, __locale_t __loc)
 libc_hidden_proto (____strtof_l_internal) libc_hidden_proto(____strtod_l_internal) libc_hidden_proto(____strtold_l_internal) libc_hidden_proto(____strtol_l_internal) libc_hidden_proto(____strtoll_l_internal) libc_hidden_proto(____strtoul_l_internal) libc_hidden_proto(____strtoull_l_internal) libc_hidden_proto(strtof) libc_hidden_proto(strtod) libc_hidden_proto(strtold) libc_hidden_proto(strtol) libc_hidden_proto(strtoll) libc_hidden_proto(strtoul) libc_hidden_proto(strtoull) extern char *__ecvt(double __value
char * __fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign)
char * __gcvt (double __value, int __ndigit, char *__buf)
int __ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len)
int __fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len)
char * __qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign)
char * __qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign)
char * __qgcvt (long double __value, int __ndigit, char *__buf)
int __qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len)
int __qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len)
void * __default_morecore (ptrdiff_t) __THROW

Variables

char **__restrict __endptr
char **__restrict int __group
char **__restrict int __locale_t __loc
int __ndigit
int int *__restrict __decpt
int int *__restrict int *__restrict __sign

Define Documentation

#define __cxa_atexit (   func,
  arg,
  d 
)    INTUSE(__cxa_atexit) (func, arg, d)

Definition at line 216 of file stdlib.h.

Definition at line 214 of file stdlib.h.


Function Documentation

float ____strtof_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __group,
__locale_t  __loc 
)
long int ____strtol_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group,
__locale_t  __loc 
)
long double ____strtold_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __group,
__locale_t  __loc 
)
__extension__ long long int ____strtoll_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group,
__locale_t  __loc 
)
unsigned long int ____strtoul_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group,
__locale_t  __loc 
)
__extension__ unsigned long long int ____strtoull_l_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group,
__locale_t  __loc 
)
int __add_to_environ ( const char *  name,
const char *  value,
const char *  combines,
int  replace 
)

Here is the caller graph for this function:

char* __canonicalize_file_name ( __const char *  __name)
int __clearenv ( void  )
int __cxa_atexit ( void(*)(void *)  func,
void *  arg,
void *  d 
)

Definition at line 33 of file cxa_atexit.c.

{
  struct exit_function *new = __new_exitfn ();

  if (new == NULL)
    return -1;

#ifdef PTR_MANGLE
  PTR_MANGLE (func);
#endif
  new->func.cxa.fn = (void (*) (void *, int)) func;
  new->func.cxa.arg = arg;
  new->func.cxa.dso_handle = d;
  atomic_write_barrier ();
  new->flavor = ef_cxa;
  return 0;
}

Here is the call graph for this function:

int __cxa_atexit_internal ( void(*)(void *)  func,
void *  arg,
void *  d 
)
void __cxa_finalize ( void *  d)

Definition at line 30 of file cxa_finalize.c.

{
  struct exit_function_list *funcs;

 restart:
  for (funcs = __exit_funcs; funcs; funcs = funcs->next)
    {
      struct exit_function *f;

      for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f)
       {
         void (*cxafn) (void *arg, int status);
         void *cxaarg;

         if ((d == NULL || d == f->func.cxa.dso_handle)
             /* We don't want to run this cleanup more than once.  */
             && (cxafn = f->func.cxa.fn,
                cxaarg = f->func.cxa.arg,
                ! catomic_compare_and_exchange_bool_acq (&f->flavor, ef_free,
                                                    ef_cxa)))
           {
             uint64_t check = __new_exitfn_called;

#ifdef PTR_DEMANGLE
             PTR_DEMANGLE (cxafn);
#endif
             cxafn (cxaarg, 0);

             /* It is possible that that last exit function registered
               more exit functions.  Start the loop over.  */
             if (__builtin_expect (check != __new_exitfn_called, 0))
              goto restart;
           }
       }
    }

  /* Remove the registered fork handlers.  We do not have to
     unregister anything if the program is going to terminate anyway.  */
#ifdef UNREGISTER_ATFORK
  if (d != NULL)
    UNREGISTER_ATFORK (d);
#endif
}

Here is the call graph for this function:

void* __default_morecore ( ptrdiff_t  )
int __drand48_iterate ( unsigned short int  __xsubi[3],
struct drand48_data *  __buffer 
)

Here is the caller graph for this function:

int __ecvt_r ( double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign,
char *__restrict  __buf,
size_t  __len 
)
int __erand48_r ( unsigned short int  __xsubi[3],
struct drand48_data *  __buffer,
double *  __result 
)

Here is the caller graph for this function:

char* __fcvt ( double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign 
)
int __fcvt_r ( double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign,
char *__restrict  __buf,
size_t  __len 
)
char* __gcvt ( double  __value,
int  __ndigit,
char *  __buf 
)
int __getpt ( void  )

Definition at line 26 of file getpt.c.

{
  __set_errno (ENOSYS);
  return -1;
}

Here is the call graph for this function:

char* __initstate ( unsigned int  __seed,
char *  __statebuf,
size_t  __statelen 
)
int __initstate_r ( unsigned int  __seed,
char *  __statebuf,
size_t  __statelen,
struct random_data __buf 
)

Here is the caller graph for this function:

int __jrand48_r ( unsigned short int  __xsubi[3],
struct drand48_data *  __buffer,
long int __result 
)

Here is the caller graph for this function:

int __lcong48_r ( unsigned short int  __param[7],
struct drand48_data *  __buffer 
)

Here is the caller graph for this function:

void* __libc_memalign ( size_t  alignment,
size_t  size 
)

Definition at line 52 of file dl-minimal.c.

{
#ifdef MAP_ANON
#define       _dl_zerofd (-1)
#else
  extern int _dl_zerofd;

  if (_dl_zerofd == -1)
    _dl_zerofd = _dl_sysdep_open_zero_fill ();
#define MAP_ANON 0
#endif

  if (alloc_end == 0)
    {
      /* Consume any unused space in the last page of our data segment.  */
      extern int _end attribute_hidden;
      alloc_ptr = &_end;
      alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0)
                             + GLRO(dl_pagesize) - 1)
                            & ~(GLRO(dl_pagesize) - 1));
    }

  /* Make sure the allocation pointer is ideally aligned.  */
  alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + align - 1)
                         & ~(align - 1));

  if (alloc_ptr + n >= alloc_end || n >= -(uintptr_t) alloc_ptr)
    {
      /* Insufficient space left; allocate another page.  */
      caddr_t page;
      size_t nup = (n + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
      if (__builtin_expect (nup == 0, 0))
       {
         if (n)
           return NULL;
         nup = GLRO(dl_pagesize);
       }
      page = __mmap (0, nup, PROT_READ|PROT_WRITE,
                   MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0);
      if (page == MAP_FAILED)
       return NULL;
      if (page != alloc_end)
       alloc_ptr = page;
      alloc_end = page + nup;
    }

  alloc_last_block = (void *) alloc_ptr;
  alloc_ptr += n;
  return alloc_last_block;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __libc_system ( const char *  line)

Definition at line 178 of file system.c.

{
  if (line == NULL)
    /* Check that we have a command processor available.  It might
       not be available after a chroot(), for example.  */
    return do_system ("exit 0") == 0;

  if (SINGLE_THREAD_P)
    return do_system (line);

  int oldtype = LIBC_CANCEL_ASYNC ();

  int result = do_system (line);

  LIBC_CANCEL_RESET (oldtype);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __nrand48_r ( unsigned short int  __xsubi[3],
struct drand48_data *  __buffer,
long int __result 
)

Here is the caller graph for this function:

int __on_exit ( void(*)(int __status, void *__arg)  __func,
void *  __arg 
)
int __posix_memalign ( void **  memptr,
size_t  alignment,
size_t  size 
)
int __posix_openpt ( int  __oflag)

Definition at line 39 of file getpt.c.

{
  static int have_no_dev_ptmx;
  int fd;

  if (!have_no_dev_ptmx)
    {
      fd = __open (_PATH_DEVPTMX, oflag);
      if (fd != -1)
       {
         struct statfs fsbuf;
         static int devpts_mounted;

         /* Check that the /dev/pts filesystem is mounted
            or if /dev is a devfs filesystem (this implies /dev/pts).  */
         if (devpts_mounted
             || (__statfs (_PATH_DEVPTS, &fsbuf) == 0
                && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
             || (__statfs (_PATH_DEV, &fsbuf) == 0
                && fsbuf.f_type == DEVFS_SUPER_MAGIC))
           {
             /* Everything is ok.  */
             devpts_mounted = 1;
             return fd;
           }

         /* If /dev/pts is not mounted then the UNIX98 pseudo terminals
             are not usable.  */
         __close (fd);
         have_no_dev_ptmx = 1;
       }
      else
       {
         if (errno == ENOENT || errno == ENODEV)
           have_no_dev_ptmx = 1;
         else
           return -1;
       }
    }

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __ptsname_r ( int  __fd,
char *  __buf,
size_t  __buflen 
)

Definition at line 48 of file ptsname.c.

{
  char peername[1024];  /* XXX */
  size_t len;
  error_t err;

  peername[0] = '\0';
  if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
    return _hurd_fd_error (fd, err);

  len = strlen (peername) + 1;
  if (len > buflen)
    return ERANGE;

  memcpy (buf, peername, len);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* __qecvt ( long double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign 
)
int __qecvt_r ( long double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign,
char *__restrict  __buf,
size_t  __len 
)
char* __qfcvt ( long double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign 
)
int __qfcvt_r ( long double  __value,
int  __ndigit,
int *__restrict  __decpt,
int *__restrict  __sign,
char *__restrict  __buf,
size_t  __len 
)
char* __qgcvt ( long double  __value,
int  __ndigit,
char *  __buf 
)
int __rand_r ( unsigned int __seed)
int __random_r ( struct random_data __buf,
int32_t __result 
)

Here is the caller graph for this function:

char* __realpath ( __const char *  __name,
char *  __resolved 
)

Here is the caller graph for this function:

int __seed48_r ( unsigned short int  __seed16v[3],
struct drand48_data *  __buffer 
)

Here is the caller graph for this function:

int __setenv ( __const char *  __name,
__const char *  __value,
int  __replace 
)

Here is the caller graph for this function:

char* __setstate ( char *  __statebuf)
int __setstate_r ( char *  __statebuf,
struct random_data __buf 
)

Here is the caller graph for this function:

int __srand48_r ( long int  __seedval,
struct drand48_data *  __buffer 
)

Definition at line 24 of file srand48_r.c.

{
  /* The standards say we only have 32 bits.  */
  if (sizeof (long int) > 4)
    seedval &= 0xffffffffl;

  buffer->__x[2] = seedval >> 16;
  buffer->__x[1] = seedval & 0xffffl;
  buffer->__x[0] = 0x330e;

  buffer->__a = 0x5deece66dull;
  buffer->__c = 0xb;
  buffer->__init = 1;

  return 0;
}

Here is the caller graph for this function:

void __srandom ( unsigned int  __seed)
int __srandom_r ( unsigned int  __seed,
struct random_data __buf 
)

Definition at line 162 of file random_r.c.

{
  int type;
  int32_t *state;
  long int i;
  long int word;
  int32_t *dst;
  int kc;

  if (buf == NULL)
    goto fail;
  type = buf->rand_type;
  if ((unsigned int) type >= MAX_TYPES)
    goto fail;

  state = buf->state;
  /* We must make sure the seed is not 0.  Take arbitrarily 1 in this case.  */
  if (seed == 0)
    seed = 1;
  state[0] = seed;
  if (type == TYPE_0)
    goto done;

  dst = state;
  word = seed;
  kc = buf->rand_deg;
  for (i = 1; i < kc; ++i)
    {
      /* This does:
          state[i] = (16807 * state[i - 1]) % 2147483647;
        but avoids overflowing 31 bits.  */
      long int hi = word / 127773;
      long int lo = word % 127773;
      word = 16807 * lo - 2836 * hi;
      if (word < 0)
       word += 2147483647;
      *++dst = word;
    }

  buf->fptr = &state[buf->rand_sep];
  buf->rptr = &state[0];
  kc *= 10;
  while (--kc >= 0)
    {
      int32_t discard;
      (void) __random_r (buf, &discard);
    }

 done:
  return 0;

 fail:
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double __strtod_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __group 
)

Here is the caller graph for this function:

float __strtof_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __group 
)

Here is the caller graph for this function:

long int __strtol_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group 
)
long double __strtold_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __group 
)
__extension__ long long int __strtoll_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group 
)

Here is the caller graph for this function:

unsigned long int __strtoul_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group 
)
__extension__ unsigned long long int __strtoull_internal ( __const char *__restrict  __nptr,
char **__restrict  __endptr,
int  __base,
int  __group 
)

Here is the caller graph for this function:

__typeof ( strtoul_l  )
__typeof ( strtod_l  )
__typeof ( strtof_l  )
int __unsetenv ( __const char *  __name)

Here is the caller graph for this function:

void _quicksort ( void *const  pbase,
size_t  total_elems,
size_t  size,
__compar_d_fn_t  cmp,
void *  arg 
)

Definition at line 90 of file qsort.c.

{
  register char *base_ptr = (char *) pbase;

  const size_t max_thresh = MAX_THRESH * size;

  if (total_elems == 0)
    /* Avoid lossage with unsigned arithmetic below.  */
    return;

  if (total_elems > MAX_THRESH)
    {
      char *lo = base_ptr;
      char *hi = &lo[size * (total_elems - 1)];
      stack_node stack[STACK_SIZE];
      stack_node *top = stack;

      PUSH (NULL, NULL);

      while (STACK_NOT_EMPTY)
        {
          char *left_ptr;
          char *right_ptr;

         /* Select median value from among LO, MID, and HI. Rearrange
            LO and HI so the three values are sorted. This lowers the
            probability of picking a pathological pivot value and
            skips a comparison for both the LEFT_PTR and RIGHT_PTR in
            the while loops. */

         char *mid = lo + size * ((hi - lo) / size >> 1);

         if ((*cmp) ((void *) mid, (void *) lo, arg) < 0)
           SWAP (mid, lo, size);
         if ((*cmp) ((void *) hi, (void *) mid, arg) < 0)
           SWAP (mid, hi, size);
         else
           goto jump_over;
         if ((*cmp) ((void *) mid, (void *) lo, arg) < 0)
           SWAP (mid, lo, size);
       jump_over:;

         left_ptr  = lo + size;
         right_ptr = hi - size;

         /* Here's the famous ``collapse the walls'' section of quicksort.
            Gotta like those tight inner loops!  They are the main reason
            that this algorithm runs much faster than others. */
         do
           {
             while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0)
              left_ptr += size;

             while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0)
              right_ptr -= size;

             if (left_ptr < right_ptr)
              {
                SWAP (left_ptr, right_ptr, size);
                if (mid == left_ptr)
                  mid = right_ptr;
                else if (mid == right_ptr)
                  mid = left_ptr;
                left_ptr += size;
                right_ptr -= size;
              }
             else if (left_ptr == right_ptr)
              {
                left_ptr += size;
                right_ptr -= size;
                break;
              }
           }
         while (left_ptr <= right_ptr);

          /* Set up pointers for next iteration.  First determine whether
             left and right partitions are below the threshold size.  If so,
             ignore one or both.  Otherwise, push the larger partition's
             bounds on the stack and continue sorting the smaller one. */

          if ((size_t) (right_ptr - lo) <= max_thresh)
            {
              if ((size_t) (hi - left_ptr) <= max_thresh)
              /* Ignore both small partitions. */
                POP (lo, hi);
              else
              /* Ignore small left partition. */
                lo = left_ptr;
            }
          else if ((size_t) (hi - left_ptr) <= max_thresh)
           /* Ignore small right partition. */
            hi = right_ptr;
          else if ((right_ptr - lo) > (hi - left_ptr))
            {
             /* Push larger left partition indices. */
              PUSH (lo, right_ptr);
              lo = left_ptr;
            }
          else
            {
             /* Push larger right partition indices. */
              PUSH (left_ptr, hi);
              hi = right_ptr;
            }
        }
    }

  /* Once the BASE_PTR array is partially sorted by quicksort the rest
     is completely sorted using insertion sort, since this is efficient
     for partitions below MAX_THRESH size. BASE_PTR points to the beginning
     of the array to sort, and END_PTR points at the very last element in
     the array (*not* one beyond it!). */

#define min(x, y) ((x) < (y) ? (x) : (y))

  {
    char *const end_ptr = &base_ptr[size * (total_elems - 1)];
    char *tmp_ptr = base_ptr;
    char *thresh = min(end_ptr, base_ptr + max_thresh);
    register char *run_ptr;

    /* Find smallest element in first threshold and place it at the
       array's beginning.  This is the smallest array element,
       and the operation speeds up insertion sort's inner loop. */

    for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
      if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0)
        tmp_ptr = run_ptr;

    if (tmp_ptr != base_ptr)
      SWAP (tmp_ptr, base_ptr, size);

    /* Insertion sort, running from left-hand-side up to right-hand-side.  */

    run_ptr = base_ptr + size;
    while ((run_ptr += size) <= end_ptr)
      {
       tmp_ptr = run_ptr - size;
       while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0)
         tmp_ptr -= size;

       tmp_ptr += size;
        if (tmp_ptr != run_ptr)
          {
            char *trav;

           trav = run_ptr + size;
           while (--trav >= run_ptr)
              {
                char c = *trav;
                char *hi, *lo;

                for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo)
                  *hi = *lo;
                *hi = c;
              }
          }
      }
  }
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 189 of file stdlib.h.

Definition at line 143 of file stdlib.h.

Definition at line 143 of file stdlib.h.

Definition at line 143 of file stdlib.h.

Definition at line 189 of file stdlib.h.

Definition at line 189 of file stdlib.h.