hush: remove superfluous comparison
[oweals/busybox.git] / shell / shell_common.c
index 51c92d60e98acd6a4f3d1631318e5bdccedf1bb8..bf56f3d78b9e4c121d3c7b8d48c879ed4b5bd18f 100644 (file)
  */
 #include "libbb.h"
 #include "shell_common.h"
+#include <sys/resource.h> /* getrlimit */
 
 const char defifsvar[] ALIGN1 = "IFS= \t\n";
+const char defoptindvar[] ALIGN1 = "OPTIND=1";
 
 
 int FAST_FUNC is_well_formed_var_name(const char *s, char terminator)
@@ -36,7 +38,7 @@ int FAST_FUNC is_well_formed_var_name(const char *s, char terminator)
 
 /* read builtin */
 
-/* Needs to be interruptible: shell mush handle traps and shell-special signals
+/* Needs to be interruptible: shell must handle traps and shell-special signals
  * while inside read. To implement this, be sure to not loop on EINTR
  * and return errno == EINTR reliably.
  */
@@ -141,7 +143,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
                        // Setting it to more than 1 breaks poll():
                        // it blocks even if there's data. !??
                        //tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
-                       /* reads would block only if < 1 char is available */
+                       /* reads will block only if < 1 char is available */
                        tty.c_cc[VMIN] = 1;
                        /* no timeout (reads block forever) */
                        tty.c_cc[VTIME] = 0;
@@ -169,7 +171,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
                int timeout;
 
                if ((bufpos & 0xff) == 0)
-                       buffer = xrealloc(buffer, bufpos + 0x100);
+                       buffer = xrealloc(buffer, bufpos + 0x101);
 
                timeout = -1;
                if (end_ms) {
@@ -202,15 +204,17 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
                c = buffer[bufpos];
                if (c == '\0')
                        continue;
-               if (backslash) {
-                       backslash = 0;
-                       if (c != '\n')
-                               goto put;
-                       continue;
-               }
-               if (!(read_flags & BUILTIN_READ_RAW) && c == '\\') {
-                       backslash = 1;
-                       continue;
+               if (!(read_flags & BUILTIN_READ_RAW)) {
+                       if (backslash) {
+                               backslash = 0;
+                               if (c != '\n')
+                                       goto put;
+                               continue;
+                       }
+                       if (c == '\\') {
+                               backslash = 1;
+                               continue;
+                       }
                }
                if (c == '\n')
                        break;
@@ -327,7 +331,7 @@ enum {
 };
 
 /* "-": treat args as parameters of option with ASCII code 1 */
-static const char ulimit_opt_string[] = "-HSa"
+static const char ulimit_opt_string[] ALIGN1 = "-HSa"
 #ifdef RLIMIT_FSIZE
                        "f::"
 #endif
@@ -379,7 +383,7 @@ static void printlim(unsigned opts, const struct rlimit *limit,
                val = limit->rlim_cur;
 
        if (val == RLIM_INFINITY)
-               printf("unlimited\n");
+               puts("unlimited");
        else {
                val >>= l->factor_shift;
                printf("%llu\n", (long long) val);
@@ -399,17 +403,9 @@ shell_builtin_ulimit(char **argv)
        /* In case getopt was already called:
         * reset the libc getopt() function, which keeps internal state.
         */
-#ifdef __GLIBC__
-       optind = 0;
-#else /* BSD style */
-       optind = 1;
-       /* optreset = 1; */
-#endif
-       /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
+       GETOPT_RESET();
 
-       argc = 1;
-       while (argv[argc])
-               argc++;
+       argc = string_array_len(argv);
 
        opts = 0;
        while (1) {
@@ -492,7 +488,6 @@ shell_builtin_ulimit(char **argv)
                        /* bad option. getopt already complained. */
                        break;
                }
-
        } /* while (there are options) */
 
        return 0;