Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 2137eb1a6cd0326510bd3b9faf8037d9bf34ca3d Mon Sep 17 00:00:00 2001 |
| 2 | From: Andrea Adami <andrea.adami@gmail.com> |
| 3 | Date: Wed, 23 May 2018 15:52:34 +0200 |
| 4 | Subject: [PATCH] common.h: replace getline() with fgets |
| 5 | |
| 6 | There is an unofficial upstream patch adding a simple getline() |
| 7 | to libmissing.h. Unfortunately the patch creates issues if the |
| 8 | toolchain is using glibc (autotools cache?) so for the moment |
| 9 | keep the old hack and wait for commits upstream. |
| 10 | |
| 11 | Fix: |
| 12 | |
| 13 | | ubi-utils/ubiformat.o: In function `prompt.constprop.4': |
| 14 | | ubiformat.c:(.text+0x70): undefined reference to `getline' |
| 15 | |
| 16 | Upstream-Status: Inappropriate [klibc specific] |
| 17 | |
| 18 | Signed-off-by: Andrea Adami <andrea.adami@gmail.com> |
| 19 | --- |
| 20 | include/common.h | 11 +++++++++++ |
| 21 | 1 file changed, 11 insertions(+) |
| 22 | |
| 23 | diff --git a/include/common.h b/include/common.h |
| 24 | index 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 | -- |
| 55 | 2.7.4 |
| 56 | |