diff options
author | tnn <tnn@pkgsrc.org> | 2015-04-19 12:22:14 +0000 |
---|---|---|
committer | tnn <tnn@pkgsrc.org> | 2015-04-19 12:22:14 +0000 |
commit | cfe76abfce218f62700bd6ee41f3581e1ca460dc (patch) | |
tree | a68b5f5757d8213cff25a9e56bdb016864ecfbc5 /pkgtools | |
parent | 4c26227cfb425e4bb3c6c38ba796eaf836bf9a1c (diff) | |
download | pkgsrc-cfe76abfce218f62700bd6ee41f3581e1ca460dc.tar.gz |
- provide getline(3) to let cwrappers build on netbsd-5
- also provide getdelim(3) for the getline(3) implementation
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/libnbcompat/files/configure.ac | 13 | ||||
-rw-r--r-- | pkgtools/libnbcompat/files/getdelim.c | 82 | ||||
-rw-r--r-- | pkgtools/libnbcompat/files/getline.c | 44 | ||||
-rw-r--r-- | pkgtools/libnbcompat/files/nbcompat/stdio.h | 10 |
4 files changed, 142 insertions, 7 deletions
diff --git a/pkgtools/libnbcompat/files/configure.ac b/pkgtools/libnbcompat/files/configure.ac index 7fc8a61cad7..fb55a65f715 100644 --- a/pkgtools/libnbcompat/files/configure.ac +++ b/pkgtools/libnbcompat/files/configure.ac @@ -1,8 +1,8 @@ -dnl $NetBSD: configure.ac,v 1.83 2014/07/25 13:26:24 jperkin Exp $ +dnl $NetBSD: configure.ac,v 1.84 2015/04/19 12:22:14 tnn Exp $ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.52) -AC_INIT([libnbcompat], [20120702], [joerg@NetBSD.org]) +AC_INIT([libnbcompat], [20150419], [joerg@NetBSD.org]) AC_CONFIG_HEADER(nbcompat/config.h) AC_ARG_PROGRAM @@ -297,10 +297,11 @@ darwin*) ;; esac -AC_REPLACE_FUNCS([asprintf err fgetln fnmatch fparseln getenv isblank \ - lchflags lchmod lchown lutimes mkdtemp mkstemp setenv setgroupent \ - setpassent setprogname shquote snprintf statvfs strdup strerror \ - strlcat strlcpy strmode strsep strtoll unsetenv usleep utimes warn +AC_REPLACE_FUNCS([asprintf err fgetln fnmatch fparseln getdelim getenv \ + getline isblank lchflags lchmod lchown lutimes mkdtemp mkstemp setenv \ + setgroupent setpassent setprogname shquote snprintf statvfs strdup \ + strerror strlcat strlcpy strmode strsep strtoll unsetenv usleep \ + utimes warn ]) AC_SEARCH_LIBS(socket, [socket network]) diff --git a/pkgtools/libnbcompat/files/getdelim.c b/pkgtools/libnbcompat/files/getdelim.c new file mode 100644 index 00000000000..84bfc4a6dd2 --- /dev/null +++ b/pkgtools/libnbcompat/files/getdelim.c @@ -0,0 +1,82 @@ +/* $NetBSD: getdelim.c,v 1.1 2015/04/19 12:22:14 tnn Exp $ */ +/* $NetBSD-src: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <nbcompat.h> +#include <nbcompat/stdio.h> +#include <nbcompat/stdlib.h> + +#if !HAVE_GETDELIM + +ssize_t +getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) +{ + char *ptr, *eptr; + + + if (*buf == NULL || *bufsiz == 0) { + *bufsiz = BUFSIZ; + if ((*buf = malloc(*bufsiz)) == NULL) + return -1; + } + + for (ptr = *buf, eptr = *buf + *bufsiz;;) { + int c = fgetc(fp); + if (c == -1) { + if (feof(fp)) { + ssize_t diff = (ssize_t)(ptr - *buf); + if (diff != 0) { + *ptr = '\0'; + return diff; + } + } + return -1; + } + *ptr++ = c; + if (c == delimiter) { + *ptr = '\0'; + return ptr - *buf; + } + if (ptr + 2 >= eptr) { + char *nbuf; + size_t nbufsiz = *bufsiz * 2; + ssize_t d = ptr - *buf; + if ((nbuf = realloc(*buf, nbufsiz)) == NULL) + return -1; + *buf = nbuf; + *bufsiz = nbufsiz; + eptr = nbuf + nbufsiz; + ptr = nbuf + d; + } + } +} + +#endif diff --git a/pkgtools/libnbcompat/files/getline.c b/pkgtools/libnbcompat/files/getline.c new file mode 100644 index 00000000000..03619f7f7d4 --- /dev/null +++ b/pkgtools/libnbcompat/files/getline.c @@ -0,0 +1,44 @@ +/* $NetBSD: getline.c,v 1.1 2015/04/19 12:22:14 tnn Exp $ */ +/* $NetBSD-src: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <nbcompat.h> +#include <nbcompat/stdio.h> + +#if !HAVE_GETLINE + +ssize_t +getline(char **buf, size_t *bufsiz, FILE *fp) +{ + return getdelim(buf, bufsiz, '\n', fp); +} + +#endif diff --git a/pkgtools/libnbcompat/files/nbcompat/stdio.h b/pkgtools/libnbcompat/files/nbcompat/stdio.h index d4b45be4f6a..5f8a6081a99 100644 --- a/pkgtools/libnbcompat/files/nbcompat/stdio.h +++ b/pkgtools/libnbcompat/files/nbcompat/stdio.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdio.h,v 1.5 2014/06/07 19:17:42 cheusov Exp $ */ +/* $NetBSD: stdio.h,v 1.6 2015/04/19 12:22:14 tnn Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -56,6 +56,14 @@ int pclose(FILE *); char *fgetln(FILE *, size_t *); #endif +#if !HAVE_GETDELIM +ssize_t getdelim(char **, size_t *, int, FILE *); +#endif + +#if !HAVE_GETLINE +ssize_t getline(char **, size_t *, FILE *); +#endif + #if !HAVE_DECL_SNPRINTF int snprintf(char *, size_t, const char *, ...); int vsnprintf(char *, size_t, const char *, va_list); |