summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/configure.ac.system2
-rw-r--r--configure.ac1
-rw-r--r--perf/Makefile.am5
-rw-r--r--perf/cairo-analyse-trace.c52
-rw-r--r--perf/cairo-perf-report.c67
-rw-r--r--perf/cairo-perf-trace.c52
-rw-r--r--test/Makefile.am6
-rw-r--r--test/cairo-test-trace.c47
-rw-r--r--util/Makefile.am2
-rw-r--r--util/cairo-missing/Makefile.am10
-rw-r--r--util/cairo-missing/Makefile.sources8
-rw-r--r--util/cairo-missing/Makefile.win3210
-rw-r--r--util/cairo-missing/cairo-missing.h49
-rw-r--r--util/cairo-missing/getline.c89
-rw-r--r--util/cairo-missing/strndup.c54
15 files changed, 237 insertions, 217 deletions
diff --git a/build/configure.ac.system b/build/configure.ac.system
index 10a2dca8..5c3f4f9a 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 71f8bf3a..4b85c8a7 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 4344b98c..88f691fc 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 1fee3cfd..96229074 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 a04db6bc..01ddeb1c 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 25a98f34..3319917f 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 d525ae3b..2fa61a54 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 96039ab2..146ca6fe 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 6c6c849f..f202f350 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 00000000..c8d6ccdf
--- /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 00000000..1a306314
--- /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 00000000..ac24a2c3
--- /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 00000000..13977567
--- /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 00000000..584c6ace
--- /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 00000000..6eabc12d
--- /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