diff -rupN old/src/libgfsm/getdelim.c new/src/libgfsm/getdelim.c --- old/src/libgfsm/getdelim.c 1970-01-01 01:00:00.000000000 +0100 +++ new/src/libgfsm/getdelim.c 2015-03-01 21:23:17.381413359 +0100 @@ -0,0 +1,54 @@ +/* Copyright (c) 2009-2013, Kevin Lawler + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, 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. + +This file is borrowed from https://github.com/asalac/kona-mingw +*/ + +#define _GNU_SOURCE +#include +#include +#include +#include + + +signed int getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { + size_t i; + if (!lineptr || !n) { + errno=EINVAL; + return -1; + } + if (!*lineptr) *n=0; + for (i=0; ; ) { + int x; + if (i>=*n) { + int tmp=*n+100; + char* new=realloc(*lineptr,tmp); + if (!new) return -1; + *lineptr=new; *n=tmp; + } + x=fgetc(stream); + if (x==EOF) { if (!i) return -1; (*lineptr)[i]=0; return i; } + (*lineptr)[i]=x; + ++i; + if (x==delim || i>=*n) break; + } + (*lineptr)[i]=0; + return i; +} + +signed int getline(char **lineptr, size_t *n, FILE *stream) { + return getdelim(lineptr,n,'\n',stream); +} + + diff -rupN old/src/libgfsm/Makefile.am new/src/libgfsm/Makefile.am --- old/src/libgfsm/Makefile.am 2014-08-22 11:17:56.000000000 +0200 +++ new/src/libgfsm/Makefile.am 2015-03-01 21:18:26.890095396 +0100 @@ -92,7 +92,8 @@ libgfsm_la_SOURCES = \ gfsmRegex.tab.y \ gfsmRegexCompiler.c \ gfsmIndexed.c \ - gfsmIndexedIO.c + gfsmIndexedIO.c \ + getdelim.c sources_argh = \ gfsmIndexed.c \ @@ -210,7 +211,7 @@ gfsmRegexCompiler.o: gfsmRegexCompiler.c AM_CPPFLAGS = -I. -I$(SRCDIR)/gnulib ## --- compiler flags (cc) -AM_CFLAGS = $(gfsm_WFLAGS) $(gfsm_OFLAGS) +AM_CFLAGS = $(gfsm_WFLAGS) $(gfsm_OFLAGS) -D_GNU_SOURCE ##----------------------------------------------------------------------- ## Additional variable: library versioning