hush: HUSH_READONLY depends on HUSH
[oweals/busybox.git] / shell / shell_common.c
index 8c9607c8c2525ed414f2653146b68290b02a7d66..bf56f3d78b9e4c121d3c7b8d48c879ed4b5bd18f 100644 (file)
@@ -21,6 +21,7 @@
 #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)
@@ -142,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;
@@ -203,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;
@@ -328,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
@@ -400,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) {