aboutsummaryrefslogtreecommitdiffstats
path: root/meta-initramfs/recipes-devtools/mtd/ubi-utils-klibc-2.0.2/0005-common.h-replace-getline-with-fgets.patch
blob: adef377b89526b0cf0e07b2c57d8398020672e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From 2137eb1a6cd0326510bd3b9faf8037d9bf34ca3d Mon Sep 17 00:00:00 2001
From: Andrea Adami <andrea.adami@gmail.com>
Date: Wed, 23 May 2018 15:52:34 +0200
Subject: [PATCH 5/5] common.h: replace getline() with fgets

There is an unofficial upstream patch adding a simple getline()
to libmissing.h. Unfortunately the patch creates issues if the
toolchain is using glibc (autotools cache?) so for the moment
keep the old hack and wait for commits upstream.

Fix:

| ubi-utils/ubiformat.o: In function `prompt.constprop.4':
| ubiformat.c:(.text+0x70): undefined reference to `getline'

Upstrea-Status: Inappropriate [klibc specific]

Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
---
 include/common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/common.h b/include/common.h
index a1d59d0..96b0bdb 100644
--- a/include/common.h
+++ b/include/common.h
@@ -126,15 +126,26 @@ extern "C" {
  */
 static inline bool prompt(const char *msg, bool def)
 {
+
+#ifndef __KLIBC__
 	char *line = NULL;
 	size_t len;
+#else
+	char *line;
+	const int sizeof_line = 2;
+	line = malloc(sizeof_line);
+#endif
 	bool ret = def;
 
 	do {
 		normsg_cont("%s (%c/%c) ", msg, def ? 'Y' : 'y', def ? 'n' : 'N');
 		fflush(stdout);
 
+#ifndef __KLIBC__
 		while (getline(&line, &len, stdin) == -1) {
+#else
+		while (fgets(line, sizeof_line, stdin) == NULL) {
+#endif
 			printf("failed to read prompt; assuming '%s'\n",
 				def ? "yes" : "no");
 			break;
-- 
2.7.4