diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-08-30 16:16:04 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-09-02 12:27:13 +0200 |
commit | 6d6bfbd641bbb4de62df704e724e507a7e55b883 (patch) | |
tree | 9a1b624ce3c02b59c67865f6743caf37b86ed2cb | |
parent | 0101a545793291d0fe76b765ba8392ade5faa1a1 (diff) |
Introduce the cairo-missing library
The cairo-missing library provides the functions which are needed in
order to correctly compile cairo (or its utilities) and which were not
found during configuration.
Fixes the build on MacOS X Lion, which failed because of collisons
between the cairo internal getline and strndup and those in libc:
cairo-analyse-trace.c:282: error: static declaration of ‘getline’ follows non-static declaration
/usr/include/stdio.h:449: error: previous declaration of ‘getline’ was here
cairo-analyse-trace.c:307: error: static declaration of ‘strndup’ follows non-static declaration
...
-rw-r--r-- | build/configure.ac.system | 2 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | perf/Makefile.am | 5 | ||||
-rw-r--r-- | perf/cairo-analyse-trace.c | 52 | ||||
-rw-r--r-- | perf/cairo-perf-report.c | 67 | ||||
-rw-r--r-- | perf/cairo-perf-trace.c | 52 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/cairo-test-trace.c | 47 | ||||
-rw-r--r-- | util/Makefile.am | 2 | ||||
-rw-r--r-- | util/cairo-missing/Makefile.am | 10 | ||||
-rw-r--r-- | util/cairo-missing/Makefile.sources | 8 | ||||
-rw-r--r-- | util/cairo-missing/Makefile.win32 | 10 | ||||
-rw-r--r-- | util/cairo-missing/cairo-missing.h | 49 | ||||
-rw-r--r-- | util/cairo-missing/getline.c | 89 | ||||
-rw-r--r-- | util/cairo-missing/strndup.c | 54 |
15 files changed, 237 insertions, 217 deletions
diff --git a/build/configure.ac.system b/build/configure.ac.system index 10a2dca89..5c3f4f9a9 100644 --- a/build/configure.ac.system +++ b/build/configure.ac.system @@ -108,7 +108,7 @@ AC_CHECK_HEADER(fenv.h, dnl check for misc headers and functions AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h]) -AC_CHECK_FUNCS([vasnprintf link ctime_r drand48 flockfile funlockfile ffs]) +AC_CHECK_FUNCS([ctime_r drand48 flockfile funlockfile getline link strndup]) dnl check for win32 headers (this detects mingw as well) AC_CHECK_HEADERS([windows.h], have_windows=yes, have_windows=no) diff --git a/configure.ac b/configure.ac index 71f8bf3a6..4b85c8a73 100644 --- a/configure.ac +++ b/configure.ac @@ -805,6 +805,7 @@ perf/micro/Makefile util/Makefile util/cairo-fdr/Makefile util/cairo-gobject/Makefile +util/cairo-missing/Makefile util/cairo-script/Makefile util/cairo-script/examples/Makefile util/cairo-sphinx/Makefile diff --git a/perf/Makefile.am b/perf/Makefile.am index 4344b98c7..88f691fc8 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -6,6 +6,7 @@ AM_CPPFLAGS = \ -I$(srcdir) \ -I$(top_srcdir)/boilerplate \ -I$(top_srcdir)/src \ + -I$(top_srcdir)/util/cairo-missing \ -I$(top_srcdir)/util/cairo-script \ -I$(top_builddir)/src \ $(CAIRO_CFLAGS) @@ -54,9 +55,11 @@ cairo_analyse_trace_SOURCES = \ $(cairo_analyse_trace_external_sources) cairo_analyse_trace_LDADD = \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ $(LDADD) cairo_analyse_trace_DEPENDENCIES = \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ $(LDADD) cairo_perf_trace_SOURCES = \ @@ -64,9 +67,11 @@ cairo_perf_trace_SOURCES = \ $(cairo_perf_trace_external_sources) cairo_perf_trace_LDADD = \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ $(LDADD) cairo_perf_trace_DEPENDENCIES = \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ $(LDADD) cairo_perf_diff_files_SOURCES = $(cairo_perf_diff_files_sources) diff --git a/perf/cairo-analyse-trace.c b/perf/cairo-analyse-trace.c index 1fee3cfd5..962290746 100644 --- a/perf/cairo-analyse-trace.c +++ b/perf/cairo-analyse-trace.c @@ -38,6 +38,7 @@ #include "cairo-boilerplate-getopt.h" #include <cairo-script-interpreter.h> +#include "cairo-missing.h" /* rudely reuse bits of the library... */ #include "../src/cairo-error-private.h" @@ -273,57 +274,6 @@ usage (const char *argv0) argv0, argv0); } -#ifndef __USE_GNU -#define POORMANS_GETLINE_BUFFER_SIZE (65536) -static ssize_t -getline (char **lineptr, - size_t *n, - FILE *stream) -{ - if (!*lineptr) - { - *n = POORMANS_GETLINE_BUFFER_SIZE; - *lineptr = (char *) malloc (*n); - } - - if (!fgets (*lineptr, *n, stream)) - return -1; - - if (!feof (stream) && !strchr (*lineptr, '\n')) - { - fprintf (stderr, "The poor man's implementation of getline in " - __FILE__ " needs a bigger buffer. Perhaps it's " - "time for a complete implementation of getline.\n"); - exit (0); - } - - return strlen (*lineptr); -} -#undef POORMANS_GETLINE_BUFFER_SIZE - -static char * -strndup (const char *s, - size_t n) -{ - size_t len; - char *sdup; - - if (!s) - return NULL; - - len = strlen (s); - len = (n < len ? n : len); - sdup = (char *) malloc (len + 1); - if (sdup) - { - memcpy (sdup, s, len); - sdup[len] = '\0'; - } - - return sdup; -} -#endif /* ifndef __USE_GNU */ - static cairo_bool_t read_excludes (cairo_perf_t *perf, const char *filename) diff --git a/perf/cairo-perf-report.c b/perf/cairo-perf-report.c index a04db6bc9..01ddeb1ca 100644 --- a/perf/cairo-perf-report.c +++ b/perf/cairo-perf-report.c @@ -25,6 +25,7 @@ * Authors: Carl Worth <cworth@cworth.org> */ +#include "cairo-missing.h" #include "cairo-perf.h" #include "cairo-stats.h" @@ -49,17 +50,6 @@ typedef ptrdiff_t ssize_t; #endif -#if !defined (__USE_GNU) && !defined(__USE_XOPEN2K8) -static ssize_t -getline (char **lineptr, - size_t *n, - FILE *stream); - -static char * -strndup (const char *s, - size_t n); -#endif - #ifdef _MSC_VER static long long strtoll (const char *nptr, @@ -230,61 +220,6 @@ test_report_parse (test_report_t *report, return TEST_REPORT_STATUS_SUCCESS; } -/* We conditionally provide a custom implementation of getline and strndup - * as needed. These aren't necessary full-fledged general purpose - * implementations. They just get the job done for our purposes. - */ -#if !defined (__USE_GNU) && !defined(__USE_XOPEN2K8) -#define POORMANS_GETLINE_BUFFER_SIZE (65536) -static ssize_t -getline (char **lineptr, - size_t *n, - FILE *stream) -{ - if (!*lineptr) - { - *n = POORMANS_GETLINE_BUFFER_SIZE; - *lineptr = (char *) malloc (*n); - } - - if (!fgets (*lineptr, *n, stream)) - return -1; - - if (!feof (stream) && !strchr (*lineptr, '\n')) - { - fprintf (stderr, "The poor man's implementation of getline in " - __FILE__ " needs a bigger buffer. Perhaps it's " - "time for a complete implementation of getline.\n"); - exit (0); - } - - return strlen (*lineptr); -} -#undef POORMANS_GETLINE_BUFFER_SIZE - -static char * -strndup (const char *s, - size_t n) -{ - size_t len; - char *sdup; - - if (!s) - return NULL; - - len = strlen (s); - len = (n < len ? n : len); - sdup = (char *) malloc (len + 1); - if (sdup) - { - memcpy (sdup, s, len); - sdup[len] = '\0'; - } - - return sdup; -} -#endif /* ifndef __USE_GNU */ - /* We provide hereafter a win32 implementation of the basename * and strtoll functions which are not available otherwise. * The basename function is fully compliant to its GNU specs. diff --git a/perf/cairo-perf-trace.c b/perf/cairo-perf-trace.c index 25a98f34c..3319917f8 100644 --- a/perf/cairo-perf-trace.c +++ b/perf/cairo-perf-trace.c @@ -32,6 +32,7 @@ #include "../cairo-version.h" /* for the real version */ +#include "cairo-missing.h" #include "cairo-perf.h" #include "cairo-stats.h" @@ -373,57 +374,6 @@ usage (const char *argv0) argv0, argv0); } -#ifndef __USE_GNU -#define POORMANS_GETLINE_BUFFER_SIZE (65536) -static ssize_t -getline (char **lineptr, - size_t *n, - FILE *stream) -{ - if (!*lineptr) - { - *n = POORMANS_GETLINE_BUFFER_SIZE; - *lineptr = (char *) malloc (*n); - } - - if (!fgets (*lineptr, *n, stream)) - return -1; - - if (!feof (stream) && !strchr (*lineptr, '\n')) - { - fprintf (stderr, "The poor man's implementation of getline in " - __FILE__ " needs a bigger buffer. Perhaps it's " - "time for a complete implementation of getline.\n"); - exit (0); - } - - return strlen (*lineptr); -} -#undef POORMANS_GETLINE_BUFFER_SIZE - -static char * -strndup (const char *s, - size_t n) -{ - size_t len; - char *sdup; - - if (!s) - return NULL; - - len = strlen (s); - len = (n < len ? n : len); - sdup = (char *) malloc (len + 1); - if (sdup) - { - memcpy (sdup, s, len); - sdup[len] = '\0'; - } - - return sdup; -} -#endif /* ifndef __USE_GNU */ - static cairo_bool_t read_excludes (cairo_perf_t *perf, const char *filename) diff --git a/test/Makefile.am b/test/Makefile.am index d525ae3bc..2fa61a546 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -114,13 +114,16 @@ cairo_test_trace_LDADD = \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ $(top_builddir)/boilerplate/libcairoboilerplate.la \ $(top_builddir)/src/libcairo.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ $(CAIRO_LDADD) \ $(SHM_LIBS) cairo_test_trace_DEPENDENCIES = \ $(top_builddir)/test/pdiff/libpdiff.la \ $(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \ $(top_builddir)/boilerplate/libcairoboilerplate.la \ - $(top_builddir)/src/libcairo.la + $(top_builddir)/src/libcairo.la \ + $(top_builddir)/util/cairo-missing/libcairo-missing.la \ + $(NULL) endif BUILT_SOURCES += cairo-test-constructors.c @@ -271,6 +274,7 @@ AM_CPPFLAGS = \ -I$(srcdir) \ -I$(srcdir)/pdiff \ -I$(top_srcdir)/boilerplate \ + -I$(top_srcdir)/util/cairo-missing \ -I$(top_srcdir)/util/cairo-script \ -I$(top_srcdir)/src \ -I$(top_builddir)/src \ diff --git a/test/cairo-test-trace.c b/test/cairo-test-trace.c index 96039ab25..146ca6fe5 100644 --- a/test/cairo-test-trace.c +++ b/test/cairo-test-trace.c @@ -59,6 +59,7 @@ #include "cairo-boilerplate-getopt.h" #include <cairo-script-interpreter.h> +#include "cairo-missing.h" #if CAIRO_HAS_SCRIPT_SURFACE #include <cairo-script.h> @@ -1415,52 +1416,6 @@ test_trace (test_trace_t *test, const char *trace) free (trace_cpy); } -#ifndef __USE_GNU -#define POORMANS_GETLINE_BUFFER_SIZE (65536) -static ssize_t -getline (char **lineptr, size_t *n, FILE *stream) -{ - if (*lineptr == NULL) { - *n = POORMANS_GETLINE_BUFFER_SIZE; - *lineptr = (char *) malloc (*n); - } - - if (! fgets (*lineptr, *n, stream)) - return -1; - - if (! feof (stream) && !strchr (*lineptr, '\n')) { - fprintf (stderr, "The poor man's implementation of getline in " - __FILE__ " needs a bigger buffer. Perhaps it's " - "time for a complete implementation of getline.\n"); - exit (0); - } - - return strlen (*lineptr); -} -#undef POORMANS_GETLINE_BUFFER_SIZE - -static char * -strndup (const char *s, size_t n) -{ - size_t len; - char *sdup; - - if (!s) - return NULL; - - len = strlen (s); - len = (n < len ? n : len); - sdup = (char *) malloc (len + 1); - if (sdup) - { - memcpy (sdup, s, len); - sdup[len] = '\0'; - } - - return sdup; -} -#endif /* ifndef __USE_GNU */ - static cairo_bool_t read_excludes (test_trace_t *test, const char *filename) { diff --git a/util/Makefile.am b/util/Makefile.am index 6c6c849ff..f202f3507 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/build/Makefile.am.common -SUBDIRS = . +SUBDIRS = . cairo-missing if CAIRO_HAS_GOBJECT_FUNCTIONS SUBDIRS += cairo-gobject diff --git a/util/cairo-missing/Makefile.am b/util/cairo-missing/Makefile.am new file mode 100644 index 000000000..c8d6ccdf1 --- /dev/null +++ b/util/cairo-missing/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/util/cairo-missing/Makefile.sources + +AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src + +lib_LTLIBRARIES = libcairo-missing.la + +libcairo_missing_la_SOURCES = \ + $(libcairo_missing_sources) \ + $(libcairo_missing_headers) \ + $(NULL) diff --git a/util/cairo-missing/Makefile.sources b/util/cairo-missing/Makefile.sources new file mode 100644 index 000000000..1a306314a --- /dev/null +++ b/util/cairo-missing/Makefile.sources @@ -0,0 +1,8 @@ +libcairo_missing_sources = \ + strndup.c \ + getline.c \ + $(NULL) + +libcairo_missing_headers = \ + cairo-missing.h \ + $(NULL) diff --git a/util/cairo-missing/Makefile.win32 b/util/cairo-missing/Makefile.win32 new file mode 100644 index 000000000..ac24a2c3d --- /dev/null +++ b/util/cairo-missing/Makefile.win32 @@ -0,0 +1,10 @@ +top_srcdir = ../../ +include $(top_srcdir)/build/Makefile.win32.common +include $(top_srcdir)/util/cairo-missing/Makefile.sources + +all: inform $(CFG)/libcairo-missing.lib + +libcairo_missing_OBJECTS = $(patsubst %.c, $(CFG)/%-static.obj, $(libcairo_missing_sources)) + +$(CFG)/libcairo-script-interpreter.lib: $(libcairo_missing_OBJECTS) + @$(AR) $(CAIRO_ARFLAGS) -OUT:$@ $(libcairo_missing_OBJECTS) diff --git a/util/cairo-missing/cairo-missing.h b/util/cairo-missing/cairo-missing.h new file mode 100644 index 000000000..13977567d --- /dev/null +++ b/util/cairo-missing/cairo-missing.h @@ -0,0 +1,49 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2011 Andrea Canciani + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the + * copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Authors: Carl Worth <cworth@cworth.org> + * Andrea Canciani <ranma42@gmail.com> + */ + +#ifndef CAIRO_MISSING_H +#define CAIRO_MISSING_H + +#include "cairo-compiler-private.h" + +#include <stdio.h> +#include <string.h> + +#ifndef HAVE_GETLINE +cairo_private ssize_t +getline (char **lineptr, size_t *n, FILE *stream); +#endif + +#ifndef HAVE_STRNDUP +cairo_private char * +strndup (const char *s, size_t n); +#endif + +#endif diff --git a/util/cairo-missing/getline.c b/util/cairo-missing/getline.c new file mode 100644 index 000000000..584c6ace4 --- /dev/null +++ b/util/cairo-missing/getline.c @@ -0,0 +1,89 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2011 Andrea Canciani + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the + * copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Authors: Carl Worth <cworth@cworth.org> + * Andrea Canciani <ranma42@gmail.com> + */ + +#include "cairo-missing.h" + +#ifndef HAVE_GETLINE + +#define GETLINE_MIN_BUFFER_SIZE 128 +ssize_t +getline (char **lineptr, + size_t *n, + FILE *stream) +{ + char *line, *tmpline; + size_t len, offset; + ssize_t ret; + + offset = 0; + len = *n; + line = *lineptr; + if (len < GETLINE_BUFFER_SIZE) { + len = GETLINE_BUFFER_SIZE; + line = NULL; + } + + if (line == NULL) { + line = (char *) malloc (len); + if (unlikely (line == NULL)) + return -1; + } + + while (1) { + if (offset + 1 == len) { + tmpline = (char *) cairo_realloc (line, len, 2); + if (unlikely (tmpline == NULL)) { + if (line != *lineptr) + free (line); + return -1; + } + len *= 2; + line = tmpline; + } + + ret = getc (stream); + if (ret == -1) + break; + + line[offset++] = ret; + if (ret == '\n') { + ret = offset; + break; + } + } + + line[offset++] = '\0'; + *lineptr = line; + *n = len; + + return ret; +} +#undef GETLINE_BUFFER_SIZE +#endif diff --git a/util/cairo-missing/strndup.c b/util/cairo-missing/strndup.c new file mode 100644 index 000000000..6eabc12d0 --- /dev/null +++ b/util/cairo-missing/strndup.c @@ -0,0 +1,54 @@ +/* cairo - a vector graphics library with display and print output + * + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2011 Andrea Canciani + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the + * copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Authors: Carl Worth <cworth@cworth.org> + * Andrea Canciani <ranma42@gmail.com> + */ + +#include "cairo-missing.h" + +#ifndef HAVE_STRNDUP +char * +strndup (const char *s, + size_t n) +{ + size_t len; + char *sdup; + + if (s == NULL) + return NULL; + + len = strlen (s); + len = MIN (n, len); + sdup = (char *) malloc (len + 1); + if (sdup != NULL) { + memcpy (sdup, s, len); + sdup[len] = '\0'; + } + + return sdup; +} +#endif |