File module-init-tools-modprobe-fastgetline.diff of Package module-init-tools

---
 modprobe.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

--- modprobe.c.orig
+++ modprobe.c
@@ -127,6 +127,7 @@ static void print_usage(const char *prog
 	exit(1);
 }
 
+#ifdef __dietlibc__	/* dietlibc does not have getline */
 static int fgetc_wrapped(FILE *file, unsigned int *linenum)
 {
 	for (;;) {
@@ -165,6 +166,46 @@ static char *getline_wrapped(FILE *file,
 		buf[i++] = ch;
 	}
 }
+#else
+char *lnbuf2 = 0; size_t blen2 = 0;
+static char *fastgetline(FILE* file, unsigned int *linenum)
+{
+	ssize_t n, n2;
+	char *lnbuf  = 0; size_t blen  = 0;
+	n = getline(&lnbuf, &blen, file);
+	if (n < 0) {
+		if (lnbuf)
+			free(lnbuf);
+		lnbuf  = NULL; blen  = 0;
+		if (lnbuf2)
+			free(lnbuf2);
+		lnbuf2 = NULL; blen2 = 0;
+		return NULL;
+	}
+	if (n && lnbuf[n-1] == '\n') /* should alway be true */
+		lnbuf[--n] = 0;
+	while (n && lnbuf[n-1] == '\\') {
+		lnbuf[--n] = 0;
+		n2 = getline(&lnbuf2, &blen2, file);
+		if (n2 < 0)
+			return lnbuf;	/* We'll be called again ... */
+		if (n2 && lnbuf2[n2-1] == '\n') /* should always be true */
+			lnbuf2[--n2] = 0;
+		if (n + n2 + 1 > blen) {
+			blen = n + n2 + 1;
+			lnbuf = NOFAIL(realloc(lnbuf, blen));
+		}
+		strcat(lnbuf, lnbuf2);
+		n += n2;
+		if (linenum)
+			(*linenum)++;
+	}
+	if (linenum)
+		(*linenum)++;
+	return lnbuf;
+}
+#define getline_wrapped fastgetline
+#endif
 
 static struct module *find_module(const char *filename, struct list_head *list)
 {
openSUSE Build Service is sponsored by