mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 16:20:17 +01:00
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 ...
This commit is contained in:
parent
0101a54579
commit
6d6bfbd641
15 changed files with 237 additions and 217 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
include $(top_srcdir)/build/Makefile.am.common
|
||||
|
||||
SUBDIRS = .
|
||||
SUBDIRS = . cairo-missing
|
||||
|
||||
if CAIRO_HAS_GOBJECT_FUNCTIONS
|
||||
SUBDIRS += cairo-gobject
|
||||
|
|
|
|||
10
util/cairo-missing/Makefile.am
Normal file
10
util/cairo-missing/Makefile.am
Normal file
|
|
@ -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)
|
||||
8
util/cairo-missing/Makefile.sources
Normal file
8
util/cairo-missing/Makefile.sources
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
libcairo_missing_sources = \
|
||||
strndup.c \
|
||||
getline.c \
|
||||
$(NULL)
|
||||
|
||||
libcairo_missing_headers = \
|
||||
cairo-missing.h \
|
||||
$(NULL)
|
||||
10
util/cairo-missing/Makefile.win32
Normal file
10
util/cairo-missing/Makefile.win32
Normal file
|
|
@ -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)
|
||||
49
util/cairo-missing/cairo-missing.h
Normal file
49
util/cairo-missing/cairo-missing.h
Normal file
|
|
@ -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
|
||||
89
util/cairo-missing/getline.c
Normal file
89
util/cairo-missing/getline.c
Normal file
|
|
@ -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
|
||||
54
util/cairo-missing/strndup.c
Normal file
54
util/cairo-missing/strndup.c
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue