From 6a75b3c0c59a8d6fc6718acaaffada3503611dd8 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 1 Nov 2001 15:41:40 +0000 Subject: 16197: `limit' accepts `unlimited'. --- Src/Builtins/rlimits.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Src/Builtins/rlimits.c') diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index 0df671786..3db47f866 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -44,12 +44,17 @@ enum { # 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) { + if (t) + *t = (char *) s + 9; + 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 +72,11 @@ zstrtorlimt(const char *s, char **t, int base) 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 * @@ -348,9 +353,10 @@ bin_limit(char *nam, char **argv, char *ops, int func) /* memory-type resource -- `k' and `M' modifiers are permitted, meaning (respectively) 2^10 and 2^20. */ val = zstrtorlimt(s, &s, 10); - if (!*s || ((*s == 'k' || *s == 'K') && !s[1])) - val *= 1024L; - else if ((*s == 'M' || *s == 'm') && !s[1]) + if (!*s || ((*s == 'k' || *s == 'K') && !s[1])) { + if (val != RLIM_INFINITY) + val *= 1024L; + } else if ((*s == 'M' || *s == 'm') && !s[1]) val *= 1024L * 1024; else { zwarnnam("limit", "unknown scaling factor: %s", s, 0); -- cgit 1.4.1