]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Avoid using readline.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 8 Apr 2011 11:02:49 +0000 (13:02 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 8 Apr 2011 11:02:49 +0000 (13:02 +0200)
src/certtool-cfg.c

index 58114988127849dcd2ff9471184e5c901d05102c..90284e317be0f7f4db35e29dcd7c1c48b3cbcfec 100644 (file)
@@ -40,7 +40,6 @@
 
 /* Gnulib portability files. */
 #include <getpass.h>
-#include "readline.h"
 #include "certtool-common.h"
 
 extern int batch;
@@ -198,6 +197,8 @@ template_parse (const char *template)
   return 0;
 }
 
+#define IS_NEWLINE(x) ((x[0] == '\n') || (x[0] == '\r'))
+
 void
 read_crt_set (gnutls_x509_crt_t crt, const char *input_str, const char *oid)
 {
@@ -208,7 +209,7 @@ read_crt_set (gnutls_x509_crt_t crt, const char *input_str, const char *oid)
   if (fgets (input, sizeof (input), stdin) == NULL)
     return;
 
-  if (strlen (input) == 1)      /* only newline */
+  if (IS_NEWLINE(input))
     return;
 
   ret =
@@ -230,7 +231,7 @@ read_crq_set (gnutls_x509_crq_t crq, const char *input_str, const char *oid)
   if (fgets (input, sizeof (input), stdin) == NULL)
     return;
 
-  if (strlen (input) == 1)      /* only newline */
+  if (IS_NEWLINE(input))
     return;
 
   ret =
@@ -247,38 +248,36 @@ read_crq_set (gnutls_x509_crq_t crq, const char *input_str, const char *oid)
 static int
 read_int_with_default (const char *input_str, int def)
 {
-  char *in;
   char *endptr;
-  long l;
+  long l, len;
+  static char input[128];
 
   fprintf (stderr, input_str, def);
-  in = readline ("");
-  if (in == NULL)
-    {
-      return def;
-    }
+  if (fgets (input, sizeof (input), stdin) == NULL)
+    return def;
 
-  l = strtol (in, &endptr, 0);
+  if (IS_NEWLINE(input))
+    return def;
 
-  if (*endptr != '\0')
+  len = strlen (input);
+
+  l = strtol (input, &endptr, 0);
+
+  if (*endptr != '\0' && *endptr != '\r' && *endptr != '\n')
     {
       fprintf (stderr, "Trailing garbage ignored: `%s'\n", endptr);
-      free (in);
       return 0;
     }
 
   if (l <= INT_MIN || l >= INT_MAX)
     {
-      fprintf (stderr, "Integer out of range: `%s'\n", in);
-      free (in);
+      fprintf (stderr, "Integer out of range: `%s'\n", input);
       return 0;
     }
 
-  if (in == endptr)
+  if (input == endptr)
     l = def;
 
-  free (in);
-
   return (int) l;
 }
 
@@ -298,6 +297,9 @@ read_str (const char *input_str)
   if (fgets (input, sizeof (input), stdin) == NULL)
     return NULL;
 
+  if (IS_NEWLINE(input))
+    return NULL;
+
   len = strlen (input);
   if ((len > 0) && (input[len - 1] == '\n'))
     input[len - 1] = 0;
@@ -318,7 +320,7 @@ read_yesno (const char *input_str)
   if (fgets (input, sizeof (input), stdin) == NULL)
     return 0;
 
-  if (strlen (input) == 1)      /* only newline */
+  if (IS_NEWLINE(input))
     return 0;
 
   if (input[0] == 'y' || input[0] == 'Y')