From b5bc28290b4c33a5cafb1d55abb1dc0f688a9d53 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Sun, 6 Jan 2019 10:53:55 -0700 Subject: [PATCH] Add hb_getline since mingw doesn't have getline function --- libhb/common.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ libhb/common.h | 2 ++ libhb/decssasub.c | 4 +-- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/libhb/common.c b/libhb/common.c index f6b4ff7f1..e501982f8 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -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 +} diff --git a/libhb/common.h b/libhb/common.h index 1cdee684e..076ecf3db 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -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]+)" diff --git a/libhb/decssasub.c b/libhb/decssasub.c index 5d0b4a3b3..2e95ba789 100644 --- a/libhb/decssasub.c +++ b/libhb/decssasub.c @@ -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); -- 2.40.0