From 94269a22013fac7bfc5591021ab142dffd45a845 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 22 Oct 2014 19:30:02 +0200
Subject: [PATCH] Fallback for missing getline (used in the testsuite).

---
 ChangeLog                |  4 ++++
 configure.ac             |  3 ++-
 testsuite/ed25519-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 966b9d60..561476e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2014-10-22  Niels Möller  <nisse@lysator.liu.se>
 
+	* configure.ac: Check for getline function.
+	* testsuite/ed25519-test.c (getline) [!HAVE_GETLINE]: Fallback
+	definition.
+
 	* Makefile.in (clean-here): Unconditionally delete .so and .dll
 	files.
 	(IMPLICIT_TARGETS): Deleted variable.
diff --git a/configure.ac b/configure.ac
index 3e464e71..bb33962c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -647,7 +647,8 @@ AC_CHECK_HEADERS([valgrind/memcheck.h])
 
 LSH_FUNC_ALLOCA
 LSH_FUNC_STRERROR
-
+# Used in the testsuite
+AC_CHECK_FUNCS(getline)
 AC_C_BIGENDIAN
 
 LSH_GCC_ATTRIBUTES
diff --git a/testsuite/ed25519-test.c b/testsuite/ed25519-test.c
index be131376..924ecea6 100644
--- a/testsuite/ed25519-test.c
+++ b/testsuite/ed25519-test.c
@@ -117,6 +117,44 @@ test_one (const char *line)
   free (msg);
 }
 
+#ifndef HAVE_GETLINE
+static ssize_t
+getline(char **lineptr, size_t *n, FILE *f)
+{
+  size_t i;
+  int c;
+  if (!*lineptr)
+    {
+      *n = 500;
+      *lineptr = xalloc (*n);
+    }
+
+  i = 0;
+  do
+    {
+      c = getc(f);
+      if (c < 0)
+	{
+	  if (i > 0)
+	    break;
+	  return -1;
+	}
+
+      (*lineptr) [i++] = c;
+      if (i == *n)
+	{
+	  *n *= 2;
+	  *lineptr = realloc (*lineptr, *n);
+	  if (!*lineptr)
+	    die ("Virtual memory exhausted.\n");
+	}
+    } while (c != '\n');
+
+  (*lineptr) [i] = 0;
+  return i;
+}
+#endif
+
 void
 test_main(void)
 {
-- 
GitLab