summarylogtreecommitdiffstats
path: root/getdelim.patch
blob: c3f023f7b4488fe87a48ca2ac97a136cd09ea080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 <k.concerns@gmail.com>
+
+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 <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <errno.h>
+
+
+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