]> granicus.if.org Git - handbrake/commitdiff
Add hb_getline since mingw doesn't have getline function
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 6 Jan 2019 17:53:55 +0000 (10:53 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 14 Jan 2019 21:36:08 +0000 (13:36 -0800)
libhb/common.c
libhb/common.h
libhb/decssasub.c

index f6b4ff7f18e8a12ae2f858503906bbe206831e58..e501982f838e5732f01a8970e78b70eee5edd3f9 100644 (file)
@@ -5705,3 +5705,69 @@ void hb_chapter_dequeue(hb_chapter_queue_t *q, hb_buffer_t *buf)
     }
 }
 
+size_t hb_getline(char ** lineptr, size_t * n, FILE * fp)
+{
+#ifdef SYS_MINGW
+    char   * bufptr = NULL;
+    char   * p      = bufptr;
+    size_t   size;
+    int      c;
+
+    if (lineptr == NULL)
+    {
+        return -1;
+    }
+    if (fp == NULL)
+    {
+        return -1;
+    }
+    if (n == NULL)
+    {
+        return -1;
+    }
+    bufptr = *lineptr;
+    size   = *n;
+
+    c = fgetc(fp);
+    if (c == EOF)
+    {
+        return -1;
+    }
+    if (bufptr == NULL)
+    {
+        bufptr = malloc(128);
+        if (bufptr == NULL)
+        {
+            return -1;
+        }
+        size = 128;
+    }
+    p = bufptr;
+    while (c != EOF)
+    {
+        if ((p - bufptr) > (size - 1))
+        {
+            size = size + 128;
+            bufptr = realloc(bufptr, size);
+            if (bufptr == NULL)
+            {
+                return -1;
+            }
+        }
+        *p++ = c;
+        if (c == '\n')
+        {
+            break;
+        }
+        c = fgetc(fp);
+    }
+
+    *p++ = '\0';
+    *lineptr = bufptr;
+    *n = size;
+
+    return p - bufptr - 1;
+#else
+    return getline(lineptr, n, fp);
+#endif
+}
index 1cdee684e68776ecdc44a994a9bf31847056e549..076ecf3dbb5ed8c1c5c73e95ef1d03dde3f00bf5 100644 (file)
@@ -1387,6 +1387,8 @@ const char * hb_x264_encopt_name( const char * name );
 const char * hb_x265_encopt_name( const char * name );
 #endif
 
+size_t hb_getline(char **lineptr, size_t *n, FILE *fp);
+
 #define HB_NEG_FLOAT_REG "(([-])?(([0-9]+([.,][0-9]+)?)|([.,][0-9]+))"
 #define HB_FLOAT_REG     "(([0-9]+([.,][0-9]+)?)|([.,][0-9]+))"
 #define HB_NEG_INT_REG   "(([-]?[0-9]+)"
index 5d0b4a3b398a2bcb2fdd56b7580ca49b4536b763..2e95ba78924c686e72a344e6810a95e57e1f7c41 100644 (file)
@@ -237,7 +237,7 @@ static int extradataInit( hb_work_private_t * pv )
         ssize_t   len;
         size_t    size = 0;
 
-        len = getline(&line, &size, pv->file);
+        len = hb_getline(&line, &size, pv->file);
         if (len < 0)
         {
             // Incomplete SSA header
@@ -472,7 +472,7 @@ static hb_buffer_t * ssa_read( hb_work_private_t * pv )
         ssize_t   len;
         size_t    size = 0;
 
-        len = getline(&line, &size, pv->file);
+        len = hb_getline(&line, &size, pv->file);
         if (len > 0 && line != NULL)
         {
             out = decode_line_to_mkv_ssa(pv, line, len);