1From 2137eb1a6cd0326510bd3b9faf8037d9bf34ca3d Mon Sep 17 00:00:00 2001 2From: Andrea Adami <andrea.adami@gmail.com> 3Date: Wed, 23 May 2018 15:52:34 +0200 4Subject: [PATCH] common.h: replace getline() with fgets 5 6There is an unofficial upstream patch adding a simple getline() 7to libmissing.h. Unfortunately the patch creates issues if the 8toolchain is using glibc (autotools cache?) so for the moment 9keep the old hack and wait for commits upstream. 10 11Fix: 12 13| ubi-utils/ubiformat.o: In function `prompt.constprop.4': 14| ubiformat.c:(.text+0x70): undefined reference to `getline' 15 16Upstream-Status: Inappropriate [klibc specific] 17 18Signed-off-by: Andrea Adami <andrea.adami@gmail.com> 19--- 20 include/common.h | 11 +++++++++++ 21 1 file changed, 11 insertions(+) 22 23diff --git a/include/common.h b/include/common.h 24index a1d59d0..96b0bdb 100644 25--- a/include/common.h 26+++ b/include/common.h 27@@ -126,15 +126,26 @@ extern "C" { 28 */ 29 static inline bool prompt(const char *msg, bool def) 30 { 31+ 32+#ifndef __KLIBC__ 33 char *line = NULL; 34 size_t len; 35+#else 36+ char *line; 37+ const int sizeof_line = 2; 38+ line = malloc(sizeof_line); 39+#endif 40 bool ret = def; 41 42 do { 43 normsg_cont("%s (%c/%c) ", msg, def ? 'Y' : 'y', def ? 'n' : 'N'); 44 fflush(stdout); 45 46+#ifndef __KLIBC__ 47 while (getline(&line, &len, stdin) == -1) { 48+#else 49+ while (fgets(line, sizeof_line, stdin) == NULL) { 50+#endif 51 printf("failed to read prompt; assuming '%s'\n", 52 def ? "yes" : "no"); 53 break; 54-- 552.7.4 56 57