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