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 /util/cairo-missing | |
parent | 0101a545793291d0fe76b765ba8392ade5faa1a1 (diff) | |
download | cairo-6d6bfbd641bbb4de62df704e724e507a7e55b883.tar.gz |
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
...
Diffstat (limited to 'util/cairo-missing')
-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 |
6 files changed, 220 insertions, 0 deletions
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 |