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