4.14.6 Utility Functions |
The first utility function is compare_ints(). This function is not used by <test.c 98> but it is included there because it is used by the test modules for all the individual tree structures.
135. <Test utility functions 135> = /* Utility functions. */ <Comparison function for ints 4>
It is prototyped in <test.h 100>:
136. <Test prototypes 102> += 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:
137. <Test utility functions 135> += /* 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:
138. <Test utility functions 135> += /* 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 ("out of memory"); return block; }