Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From 5d4a66b502003ef385dab31a17012246407e7364 Mon Sep 17 00:00:00 2001 |
| 2 | From: Andrea Adami <andrea.adami@gmail.com> |
| 3 | Date: Sun, 29 Jun 2014 00:44:03 +0200 |
| 4 | Subject: [PATCH 5/9] common.h: more workarounds for klibc compatibility |
| 5 | |
| 6 | Patch is addressing two issues: |
| 7 | * First, Klibc doesn't have rpmatch(). |
| 8 | * Second, Klibc lacks getline() |
| 9 | |
| 10 | Fixes: |
| 11 | | LD ubi-utils/ubiformat |
| 12 | | .../git/ubi-utils/ubiformat.o: In function `prompt': |
| 13 | | .../git/./include/common.h:157: undefined reference to `getline' |
| 14 | | .../git/./include/common.h:164: undefined reference to `rpmatch' |
| 15 | | .../git/./include/common.h:157: undefined reference to `getline' |
| 16 | | .../git/./include/common.h:164: undefined reference to `rpmatch' |
| 17 | |
| 18 | Upstream-Status: Submitted |
| 19 | |
| 20 | Signed-off-by: Andrea Adami <andrea.adami@gmail.com> |
| 21 | --- |
| 22 | include/common.h | 8 +++++--- |
| 23 | 1 file changed, 5 insertions(+), 3 deletions(-) |
| 24 | |
| 25 | diff --git a/include/common.h b/include/common.h |
| 26 | index 5a20964..2f51e1c 100644 |
| 27 | --- a/include/common.h |
| 28 | +++ b/include/common.h |
| 29 | @@ -161,15 +161,17 @@ static inline int __rpmatch(const char *resp) |
| 30 | */ |
| 31 | static inline bool prompt(const char *msg, bool def) |
| 32 | { |
| 33 | - char *line = NULL; |
| 34 | - size_t len; |
| 35 | + char *line; |
| 36 | bool ret = def; |
| 37 | |
| 38 | + const int sizeof_line = 2; |
| 39 | + line = malloc(sizeof_line); |
| 40 | + |
| 41 | do { |
| 42 | normsg_cont("%s (%c/%c) ", msg, def ? 'Y' : 'y', def ? 'n' : 'N'); |
| 43 | fflush(stdout); |
| 44 | |
| 45 | - while (getline(&line, &len, stdin) == -1) { |
| 46 | + while (fgets(line, sizeof_line, stdin) == NULL) { |
| 47 | printf("failed to read prompt; assuming '%s'\n", |
| 48 | def ? "yes" : "no"); |
| 49 | break; |
| 50 | -- |
| 51 | 2.7.4 |
| 52 | |