diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2007-04-20 00:34:51 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2007-04-20 00:52:03 -0400 |
commit | 2e709321d858a048731eeaaca4a13a96de739e3f (patch) | |
tree | e9303b0264f33620fe63e32e3926a655c9013c3a /boilerplate | |
parent | 5331445c12756293a915420a26ab5553fc7db3fc (diff) |
[boilerplate] Move xasprintf to xmalloc.c
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/cairo-boilerplate.c | 45 | ||||
-rw-r--r-- | boilerplate/cairo-boilerplate.h | 32 | ||||
-rw-r--r-- | boilerplate/xmalloc.c | 50 | ||||
-rw-r--r-- | boilerplate/xmalloc.h | 9 |
4 files changed, 70 insertions, 66 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 6df0c8f85..57e8312f5 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -57,9 +57,7 @@ #include "cairo-boilerplate-xlib-private.h" #endif -#include <stdio.h> #include <stdlib.h> -#include <stdarg.h> #include <ctype.h> #include <assert.h> @@ -558,46 +556,3 @@ cairo_boilerplate_surface_set_user_data (cairo_surface_t *surface, exit (1); } } - -void -xasprintf (char **strp, const char *fmt, ...) -{ -#ifdef HAVE_VASPRINTF - va_list va; - int ret; - - va_start (va, fmt); - ret = vasprintf (strp, fmt, va); - va_end (va); - - if (ret < 0) { - CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n"); - exit (1); - } -#else /* !HAVE_VASNPRINTF */ -#define BUF_SIZE 1024 - va_list va; - char buffer[BUF_SIZE]; - int ret; - - va_start (va, fmt); - ret = vsnprintf (buffer, sizeof(buffer), fmt, va); - va_end (va); - - if (ret < 0) { - CAIRO_BOILERPLATE_LOG ("Failure in vsnprintf\n"); - exit (1); - } - - if (strlen (buffer) == sizeof(buffer) - 1) { - CAIRO_BOILERPLATE_LOG ("Overflowed fixed buffer\n"); - exit (1); - } - - *strp = strdup (buffer); - if (!*strp) { - CAIRO_BOILERPLATE_LOG ("Out of memory\n"); - exit (1); - } -#endif /* !HAVE_VASNPRINTF */ -} diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h index 5b4c2176f..aa23e1ce9 100644 --- a/boilerplate/cairo-boilerplate.h +++ b/boilerplate/cairo-boilerplate.h @@ -67,18 +67,16 @@ #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.) #endif -#include "xmalloc.h" - #ifndef CAIRO_BOILERPLATE_LOG #define CAIRO_BOILERPLATE_LOG(...) fprintf(stderr, __VA_ARGS__) #endif -/* A fake format we use for the flattened ARGB output of the PS and - * PDF surfaces. */ -#define CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED ((unsigned int) -1) - -const char * -cairo_boilerplate_content_name (cairo_content_t content); +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) \ + __attribute__((__format__(__printf__, fmt_index, va_index))) +#else +#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) +#endif #ifndef FALSE #define FALSE 0 @@ -88,6 +86,14 @@ cairo_boilerplate_content_name (cairo_content_t content); #define TRUE 1 #endif + +/* A fake format we use for the flattened ARGB output of the PS and + * PDF surfaces. */ +#define CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED ((unsigned int) -1) + +const char * +cairo_boilerplate_content_name (cairo_content_t content); + typedef enum { CAIRO_BOILERPLATE_MODE_TEST, CAIRO_BOILERPLATE_MODE_PERF @@ -130,20 +136,12 @@ cairo_boilerplate_get_targets (int *num_targets, cairo_bool_t *limited_targets); void cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets); -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \ - __attribute__((__format__(__printf__, fmt_index, va_index))) -#else -#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) -#endif - void cairo_boilerplate_surface_set_user_data (cairo_surface_t *surface, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy); -void -xasprintf (char **strp, const char *fmt, ...) CAIRO_PRINTF_FORMAT(2, 3); +#include "xmalloc.h" #endif diff --git a/boilerplate/xmalloc.c b/boilerplate/xmalloc.c index 8da056809..ddd5cccaf 100644 --- a/boilerplate/xmalloc.c +++ b/boilerplate/xmalloc.c @@ -23,12 +23,13 @@ * Author: Carl D. Worth <cworth@cworth.org> */ -#include <stdio.h> -#include <stdlib.h> - #include "cairo-boilerplate.h" #include "xmalloc.h" +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + void * xmalloc (size_t size) { @@ -68,3 +69,46 @@ xrealloc (void *buf, size_t size) return buf; } + +void +xasprintf (char **strp, const char *fmt, ...) +{ +#ifdef HAVE_VASPRINTF + va_list va; + int ret; + + va_start (va, fmt); + ret = vasprintf (strp, fmt, va); + va_end (va); + + if (ret < 0) { + CAIRO_BOILERPLATE_LOG ("Error: Out of memory. Exiting.\n"); + exit (1); + } +#else /* !HAVE_VASNPRINTF */ +#define BUF_SIZE 1024 + va_list va; + char buffer[BUF_SIZE]; + int ret; + + va_start (va, fmt); + ret = vsnprintf (buffer, sizeof(buffer), fmt, va); + va_end (va); + + if (ret < 0) { + CAIRO_BOILERPLATE_LOG ("Failure in vsnprintf\n"); + exit (1); + } + + if (strlen (buffer) == sizeof(buffer) - 1) { + CAIRO_BOILERPLATE_LOG ("Overflowed fixed buffer\n"); + exit (1); + } + + *strp = strdup (buffer); + if (!*strp) { + CAIRO_BOILERPLATE_LOG ("Out of memory\n"); + exit (1); + } +#endif /* !HAVE_VASNPRINTF */ +} diff --git a/boilerplate/xmalloc.h b/boilerplate/xmalloc.h index 1f0fadf6e..b0e891f22 100644 --- a/boilerplate/xmalloc.h +++ b/boilerplate/xmalloc.h @@ -26,15 +26,22 @@ #ifndef _XMALLOC_H_ #define _XMALLOC_H_ -#include <stdlib.h> +#include "cairo-boilerplate.h" +#define xmalloc cairo_boilerplate_xmalloc void * xmalloc (size_t size); +#define xcalloc cairo_boilerplate_xcalloc void * xcalloc (size_t nmemb, size_t size); +#define xrealloc cairo_boilerplate_recalloc void * xrealloc (void *buf, size_t size); +#define xasprintf cairo_boilerplate_xasprintf +void +xasprintf (char **strp, const char *fmt, ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3); + #endif |