From 02875dc51fe3be940ae0d8d61dc264731ee12a76 Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 13 Jan 2010 05:40:58 +0000 Subject: Add a static getline implementation for FreeBSD < 8.0. git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@13447 df743ca5-7f9a-e211-a948-0013205c9059 --- math/gcalctool/files/patch-src_gcalccmd.c | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 math/gcalctool/files/patch-src_gcalccmd.c (limited to 'math/gcalctool') diff --git a/math/gcalctool/files/patch-src_gcalccmd.c b/math/gcalctool/files/patch-src_gcalccmd.c new file mode 100644 index 000000000..7a3c1a7a7 --- /dev/null +++ b/math/gcalctool/files/patch-src_gcalccmd.c @@ -0,0 +1,87 @@ +--- src/gcalccmd.c.orig 2010-01-13 00:30:10.000000000 -0500 ++++ src/gcalccmd.c 2010-01-13 00:39:51.000000000 -0500 +@@ -22,12 +22,84 @@ + #include + #include + #include ++#include + #include + + #include "mp-equation.h" + + #define MAXLINE 1024 + ++#if __FreeBSD_version < 800067 ++static ssize_t ++getline (char **lineptr, size_t *n, FILE *stream) ++{ ++ char *line, *p; ++ long size, copy; ++ ++ if (lineptr == NULL || n == NULL) { ++ errno = EINVAL; ++ return (ssize_t) -1; ++ } ++ ++ if (ferror (stream)) ++ return (ssize_t) -1; ++ ++ /* Make sure we have a line buffer to start with. */ ++ if (*lineptr == NULL || *n < 2) /* !seen and no buf yet need 2 chars. */ { ++#ifndef MAX_CANON ++#define MAX_CANON 256 ++#endif ++ if (!*lineptr) ++ line = (char *) malloc (MAX_CANON); ++ else ++ line = (char *) realloc (*lineptr, MAX_CANON); ++ if (line == NULL) ++ return (ssize_t) -1; ++ *lineptr = line; ++ *n = MAX_CANNON; ++ } ++ ++ line = *lineptr; ++ size = *n; ++ ++ copy = size; ++ p = line; ++ ++ while (1) { ++ long len; ++ ++ while (--copy > 0) { ++ int c = getc (stream); ++ ++ if (c == EOF) ++ goto lose; ++ else if ((*p++ = c) == '\n') ++ goto win; ++ } ++ ++ /* Need to enlarge the line buffer. */ ++ len = p - line; ++ size *= 2; ++ line = (char *) realloc (line, size); ++ if (line == NULL) ++ goto lose; ++ *lineptr = line; ++ *n = size; ++ p = line + len; ++ copy = size - len; ++ } ++ ++lose: ++ if (p == *lineptr) ++ return (ssize_t) -1; ++ ++ /* Return a partial line since we got an error in the middle. */ ++win: ++ *p = '\0'; ++ return p - *lineptr; ++} ++#endif ++ + static void + solve(const char *equation) + { -- cgit v1.2.3