]> www.infradead.org Git - mtd-utils.git/commitdiff
Replace rpmatch() usage with checking first character of line
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 2 Mar 2017 10:40:36 +0000 (11:40 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 2 Mar 2017 10:43:58 +0000 (11:43 +0100)
This is based on the patch from Khem Raj used by openembedded. In
addition to the original patch, this also removes the fallback
implementation that was provided for C libraries that don't implement
rpmatch.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
include/common.h

index d0c706d6f23a9ee2783facc8905c4c4dc3353705..d6092571779706410e28fac018b942bae85f9395 100644 (file)
@@ -129,21 +129,6 @@ extern "C" {
        fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \
 } while(0)
 
-/* uClibc versions before 0.9.34 and musl don't have rpmatch() */
-#if defined(__UCLIBC__) && \
-               (__UCLIBC_MAJOR__ == 0 && \
-               (__UCLIBC_MINOR__ < 9 || \
-               (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 34))) || \
-       !defined(__GLIBC__)
-#undef rpmatch
-#define rpmatch __rpmatch
-static inline int __rpmatch(const char *resp)
-{
-    return (resp[0] == 'y' || resp[0] == 'Y') ? 1 :
-       (resp[0] == 'n' || resp[0] == 'N') ? 0 : -1;
-}
-#endif
-
 /**
  * prompt the user for confirmation
  */
@@ -164,10 +149,12 @@ static inline bool prompt(const char *msg, bool def)
                }
 
                if (strcmp("\n", line) != 0) {
-                       switch (rpmatch(line)) {
-                       case 0: ret = false; break;
-                       case 1: ret = true; break;
-                       case -1:
+                       switch (line[0]) {
+                       case 'N':
+                       case 'n': ret = false; break;
+                       case 'Y':
+                       case 'y': ret = true; break;
+                       default:
                                puts("unknown response; please try again");
                                continue;
                        }