00db10
commit c079afb7724ce4b9ff2d6b1ca4d7e3cdebcbcd1f
00db10
Author: Roland McGrath <roland@hack.frob.com>
00db10
Date:   Fri Sep 12 14:58:55 2014 -0700
00db10
00db10
    Don't use a nested function in rpmatch.
00db10
00db10
diff --git a/stdlib/rpmatch.c b/stdlib/rpmatch.c
00db10
index 31285879ee7e6ff6..8c6290551bae1bcf 100644
00db10
--- a/stdlib/rpmatch.c
00db10
+++ b/stdlib/rpmatch.c
00db10
@@ -22,42 +22,40 @@
00db10
 #include <regex.h>
00db10
 
00db10
 
00db10
-int
00db10
-rpmatch (response)
00db10
-     const char *response;
00db10
+/* Match against one of the response patterns, compiling the pattern
00db10
+   first if necessary.  */
00db10
+static int
00db10
+try (const char *response,
00db10
+     const int tag, const int match, const int nomatch,
00db10
+     const char **lastp, regex_t *re)
00db10
 {
00db10
-  /* Match against one of the response patterns, compiling the pattern
00db10
-     first if necessary.  */
00db10
-  auto int try (const int tag, const int match, const int nomatch,
00db10
-		const char **lastp, regex_t *re);
00db10
-
00db10
-  int try (const int tag, const int match, const int nomatch,
00db10
-	   const char **lastp, regex_t *re)
00db10
+  const char *pattern = nl_langinfo (tag);
00db10
+  if (pattern != *lastp)
00db10
     {
00db10
-      const char *pattern = nl_langinfo (tag);
00db10
-      if (pattern != *lastp)
00db10
-	{
00db10
-	  /* The pattern has changed.  */
00db10
-	  if (*lastp)
00db10
-	    {
00db10
-	      /* Free the old compiled pattern.  */
00db10
-	      __regfree (re);
00db10
-	      *lastp = NULL;
00db10
-	    }
00db10
-	  /* Compile the pattern and cache it for future runs.  */
00db10
-	  if (__regcomp (re, pattern, REG_EXTENDED) != 0)
00db10
-	    return -1;
00db10
-	  *lastp = pattern;
00db10
-	}
00db10
-
00db10
-      /* Try the pattern.  */
00db10
-      return __regexec (re, response, 0, NULL, 0) == 0 ? match : nomatch;
00db10
+      /* The pattern has changed.  */
00db10
+      if (*lastp != NULL)
00db10
+        {
00db10
+          /* Free the old compiled pattern.  */
00db10
+          __regfree (re);
00db10
+          *lastp = NULL;
00db10
+        }
00db10
+      /* Compile the pattern and cache it for future runs.  */
00db10
+      if (__regcomp (re, pattern, REG_EXTENDED) != 0)
00db10
+        return -1;
00db10
+      *lastp = pattern;
00db10
     }
00db10
 
00db10
+  /* Try the pattern.  */
00db10
+  return __regexec (re, response, 0, NULL, 0) == 0 ? match : nomatch;
00db10
+}
00db10
+
00db10
+int
00db10
+rpmatch (const char *response)
00db10
+{
00db10
   /* We cache the response patterns and compiled regexps here.  */
00db10
   static const char *yesexpr, *noexpr;
00db10
   static regex_t yesre, nore;
00db10
 
00db10
-  return (try (YESEXPR, 1, 0, &yesexpr, &yesre) ?:
00db10
-	  try (NOEXPR, 0, -1, &noexpr, &nore));
00db10
+  return (try (response, YESEXPR, 1, 0, &yesexpr, &yesre) ?:
00db10
+	  try (response, NOEXPR, 0, -1, &noexpr, &nore));
00db10
 }