www.delorie.com/gnu/docs/avl/libavl_85.html   search  
Buy GNU books!

GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.14.6 Utility Functions

The first utility function is compare_ints(). This function is not used by &#60;@xref{\NODE\, , test.c.&#62;,97} but it is included there because it is used by the test modules for all the individual tree structures.

/* Utility functions. */
&#60;@xref{\NODE\, , Comparison function for int.&#62;s,3}
See also @refalso{136 This code is included in @refalso{97

It is prototyped in &#60;@xref{\NODE\, , test.h.&#62;,99}:

int compare_ints (const void *pa, const void *pb, void *param);

The fail() function prints a provided error message to stderr, formatting it as with printf(), and terminates the program unsuccessfully:

/* Prints message on stderr, which is formatted as for printf(), 
   and terminates the program unsuccessfully. */
static void 
fail (const char *message, ...)
{ va_list args; fprintf (stderr, "%s:", pgm_name); va_start (args, message); vfprintf (stderr, message, args); va_end (args); putchar ('\n'); exit (EXIT_FAILURE); }

Finally, the xmalloc() function is a malloc() wrapper that aborts the program if allocation fails:

/* Allocates and returns a pointer to size bytes of memory.
   Aborts if allocation fails. */
static void *
xmalloc (size_t size)
{ void *block = malloc (size); if (block == NULL && size != 0) fail ("outofmemory"); return block; }

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003