aboutsummaryrefslogtreecommitdiff
path: root/multimedia/vdr-plugin-infosatepg/files/patch-readline.cpp
blob: c16dbcdbb13a4651fd55471a7277eaa2598d7a86 (plain) (blame)
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
--- a/readline.cpp
+++ b/readline.cpp
@@ -10,6 +10,15 @@
 #include <stdio.h>
 #include "readline.h"
 
+#ifdef __FreeBSD__
+#include <string.h>
+#if __FreeBSD_version > 800000
+#define HAVE_GETLINE
+#endif
+#else
+#define HAVE_GETLINE
+#endif
+
 extern char *strcatrealloc(char *dest, const char *src);
 
 // --- cReadLineInfosatepg ---------------------------------------------------
@@ -36,7 +45,31 @@ char *cReadLineInfosatepg::Read(FILE *f,
   do
   {
     ext=false;
+#ifndef HAVE_GETLINE
+    size_t n;
+
+    if (!tempbuffer)
+    {
+      if (!(tempbuffer = (char *)malloc(tempsize = 4096)))
+        return NULL;
+    }
+    if (!fgets(tempbuffer, tempsize, f))
+    {
+      if (tempbuffer) free(tempbuffer);
+      return buffer;
+    }
+    while ((n = strlen(tempbuffer)) >= tempsize - 1 &&
+        tempbuffer[n - 1] != '\n')
+    {
+      if (!(tempbuffer = (char *)realloc(tempbuffer, tempsize * 2)))
+        return NULL;
+      tempsize *= 2;
+      if (!fgets(tempbuffer + n, tempsize - n, f))
+        break;
+    }
+#else
     int n = getline(&tempbuffer, &tempsize, f);
+#endif
     if (n > 0)
     {
       if (tempbuffer[n-1] == '\n')