pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/libnbcompat/files - provide getline(3) to let...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5fba24f4d8f9
branches:  trunk
changeset: 650166:5fba24f4d8f9
user:      tnn <tnn%pkgsrc.org@localhost>
date:      Sun Apr 19 12:22:14 2015 +0000

description:
- provide getline(3) to let cwrappers build on netbsd-5
- also provide getdelim(3) for the getline(3) implementation

diffstat:

 pkgtools/libnbcompat/files/configure.ac     |  13 ++--
 pkgtools/libnbcompat/files/getdelim.c       |  82 +++++++++++++++++++++++++++++
 pkgtools/libnbcompat/files/getline.c        |  44 +++++++++++++++
 pkgtools/libnbcompat/files/nbcompat/stdio.h |  10 +++-
 4 files changed, 142 insertions(+), 7 deletions(-)

diffs (188 lines):

diff -r 02012d4c8b9b -r 5fba24f4d8f9 pkgtools/libnbcompat/files/configure.ac
--- a/pkgtools/libnbcompat/files/configure.ac   Sun Apr 19 12:18:44 2015 +0000
+++ b/pkgtools/libnbcompat/files/configure.ac   Sun Apr 19 12:22:14 2015 +0000
@@ -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@localhost])
+AC_INIT([libnbcompat], [20150419], [joerg%NetBSD.org@localhost])
 AC_CONFIG_HEADER(nbcompat/config.h)
 AC_ARG_PROGRAM
 
@@ -297,10 +297,11 @@
        ;;
 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 -r 02012d4c8b9b -r 5fba24f4d8f9 pkgtools/libnbcompat/files/getdelim.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/libnbcompat/files/getdelim.c     Sun Apr 19 12:22:14 2015 +0000
@@ -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 -r 02012d4c8b9b -r 5fba24f4d8f9 pkgtools/libnbcompat/files/getline.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/libnbcompat/files/getline.c      Sun Apr 19 12:22:14 2015 +0000
@@ -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 -r 02012d4c8b9b -r 5fba24f4d8f9 pkgtools/libnbcompat/files/nbcompat/stdio.h
--- a/pkgtools/libnbcompat/files/nbcompat/stdio.h       Sun Apr 19 12:18:44 2015 +0000
+++ b/pkgtools/libnbcompat/files/nbcompat/stdio.h       Sun Apr 19 12:22:14 2015 +0000
@@ -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 @@
 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);



Home | Main Index | Thread Index | Old Index