Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: "limit" should not set a limit to 0 on bad input



On Oct 22,  5:50pm, Peter Stephenson wrote:
} Subject: Re: PATCH: "limit" should not set a limit to 0 on bad input
}
} Bart Schaefer wrote:
} > Remind me again why "limit" doesn't understand a spec of "unlimited"?
} 
} You're supposed to use `unlimit', I assume.  But it would make perfect
} sense to allow `unlimited' given that that's what it outputs.

See potential patch below.

} Probably a good idea to apply this to 4.0.

Did that.

Index: Src/Builtins/rlimits.c
===================================================================
--- Src/Builtins/rlimits.c	2001/10/22 17:03:58	1.2
+++ Src/Builtins/rlimits.c	2001/10/22 17:17:16
@@ -44,12 +44,14 @@
 
 # include "rlimits.h"
 
-# if defined(RLIM_T_IS_QUAD_T) || defined(RLIM_T_IS_LONG_LONG) || defined(RLIM_T_IS_UNSIGNED)
 static rlim_t
 zstrtorlimt(const char *s, char **t, int base)
 {
     rlim_t ret = 0;
- 
+
+    if (strcmp(s, "unlimited") == 0)
+	return RLIM_INFINITY;
+# if defined(RLIM_T_IS_QUAD_T) || defined(RLIM_T_IS_LONG_LONG) || defined(RLIM_T_IS_UNSIGNED)
     if (!base) {
 	if (*s != '0')
 	    base = 10;
@@ -67,11 +69,11 @@
 	    ret = ret * base + (idigit(*s) ? (*s - '0') : (*s & 0x1f) + 9);
     if (t)
 	*t = (char *)s;
-    return ret;
-}
 # else /* !RLIM_T_IS_QUAD_T && !RLIM_T_IS_LONG_LONG && !RLIM_T_IS_UNSIGNED */
-#  define zstrtorlimt(a, b, c)	zstrtol((a), (b), (c))
+    ret = zstrtol(s, t, base);
 # endif /* !RLIM_T_IS_QUAD_T && !RLIM_T_IS_LONG_LONG && !RLIM_T_IS_UNSIGNED */
+    return ret;
+}
 
 /* Display resource limits.  hard indicates whether `hard' or `soft'  *
  * limits should be displayed.  lim specifies the limit, or may be -1 *
@@ -317,7 +319,7 @@
 	     * together more than one of these.  It's easier to understand from *
 	     * the code:                                                        */
 	    val = zstrtorlimt(s, &s, 10);
-	    if (*s) {
+	    if (*s && val != RLIM_INFINITY) {
 		if ((*s == 'h' || *s == 'H') && !s[1])
 		    val *= 3600L;
 		else if ((*s == 'm' || *s == 'M') && !s[1])
@@ -334,7 +336,7 @@
 	    permitted. */
 	    char *t = s;
 	    val = zstrtorlimt(t, &s, 10);
-	    if (s == t) {
+	    if (s == t && val != RLIM_INFINITY) {
 		zwarnnam("limit", "limit must be a number", NULL, 0);
 		return 1;
 	    }
@@ -346,7 +348,7 @@
 		val *= 1024L;
 	    else if ((*s == 'M' || *s == 'm') && !s[1])
 		val *= 1024L * 1024;
-	    else {
+	    else if (val != RLIM_INFINITY) {
 		zwarnnam("limit", "unknown scaling factor: %s", s, 0);
 		return 1;
 	    }


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author