Replace systemlinux.org URL and email address.
[adu.git] / interactive.c
index 913d3f06308fed446b72ce67510c2288eab13e53..05830f1bf8fe860d04ebede3aeaedc40a90c3b18 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -12,6 +12,7 @@
 #include "format.h"
 #include "user.h"
 #include "string.h"
+#include "cmdline.h"
 #include "select.cmdline.h"
 #include "select.h"
 #include "error.h"
@@ -109,7 +110,6 @@ static int icom_reset(__a_unused char *line)
 
 static int icom_set(char *line)
 {
-       int ret;
        struct select_cmdline_parser_params params = {
                .override = 1,
                .initialize = 0,
@@ -126,12 +126,24 @@ static int icom_set(char *line)
        fi = NULL;
        free(admissible_uids);
        admissible_uids = NULL;
-       ret = parse_select_options(line, &params, &admissible_uids, &fi);
-       if (ret >= 0)
-               return ret;
-       return icom_reset(NULL);
+       return parse_select_options(line, &params, &admissible_uids, &fi);
 }
 
+/**
+ * Wrapper for isspace.
+ * NetBSD needs this.
+ */
+/*
+ * The values should be cast to an unsigned char first, then to int.
+ * Why? Because the isdigit (as do all other is/to functions/macros)
+ * expect a number from 0 upto and including 255 as their (int) argument.
+ * Because char is signed on most systems, casting it to int immediately
+ * gives the functions an argument between -128 and 127 (inclusive),
+ * which they will use as an array index, and which will thus fail
+ * horribly for characters which have their most significant bit set.
+ */
+#define adu_isspace(c) isspace((int)(unsigned char)(c))
+
 static int exec_interactive_command(char *line)
 {
        const char const *delim = "\t\n\f\r\v ";
@@ -144,7 +156,7 @@ static int exec_interactive_command(char *line)
                return 1;
        len = strlen(line);
 
-       while (len && isspace(line[len - 1])) {
+       while (len && adu_isspace(line[len - 1])) {
                line[len - 1] = '\0';
                len--;
        }