about summary refs log tree commit diff
path: root/Src/Builtins/rlimits.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-10-18 10:24:52 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-10-18 10:24:52 +0000
commit9411b0e51a065a19e0c17caaf2d61298377a47c7 (patch)
tree25cfc121fae319e8407c630e9c29f9949bacdde8 /Src/Builtins/rlimits.c
parent910dc80a58cf3bcf91c51a72f117a46a7c9f77cf (diff)
downloadzsh-9411b0e51a065a19e0c17caaf2d61298377a47c7.tar.gz
zsh-9411b0e51a065a19e0c17caaf2d61298377a47c7.tar.xz
zsh-9411b0e51a065a19e0c17caaf2d61298377a47c7.zip
zsh-workers/8320
Diffstat (limited to 'Src/Builtins/rlimits.c')
-rw-r--r--Src/Builtins/rlimits.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index 8ffcf5cdf..3f0ad7ed5 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -32,6 +32,13 @@
 
 #if defined(HAVE_GETRLIMIT) && defined(RLIM_INFINITY)
 
+enum {
+    ZLIMTYPE_MEMORY,
+    ZLIMTYPE_NUMBER,
+    ZLIMTYPE_TIME,
+    ZLIMTYPE_UNKNOWN
+};
+
 /* Generated rec array containing limits required for the limit builtin.     *
  * They must appear in this array in numerical order of the RLIMIT_* macros. */
 
@@ -85,22 +92,15 @@ showlimits(int hard, int lim)
 	    val = (hard) ? limits[rt].rlim_max : limits[rt].rlim_cur;
 	    if (val == RLIM_INFINITY)
 		printf("unlimited\n");
-	    else if (rt==RLIMIT_CPU)
+	    else if (limtype[rt] == ZLIMTYPE_TIME) {
 		/* time-type resource -- display as hours, minutes and
 		seconds. */
 		printf("%d:%02d:%02d\n", (int)(val / 3600),
 		       (int)(val / 60) % 60, (int)(val % 60));
-# ifdef RLIMIT_NPROC
-	    else if (rt == RLIMIT_NPROC)
+	    } else if (limtype[rt] == ZLIMTYPE_NUMBER || limtype[rt] == ZLIMTYPE_UNKNOWN) {
 		/* pure numeric resource */
 		printf("%d\n", (int)val);
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_NOFILE
-	    else if (rt == RLIMIT_NOFILE)
-		/* pure numeric resource */
-		printf("%d\n", (int)val);
-# endif /* RLIMIT_NOFILE */
-	    else if (val >= 1024L * 1024L)
+	    } else if (val >= 1024L * 1024L)
 		/* memory resource -- display with `K' or `M' modifier */
 # ifdef RLIM_T_IS_QUAD_T
 		printf("%qdMB\n", val / (1024L * 1024L));
@@ -297,7 +297,7 @@ bin_limit(char *nam, char **argv, char *ops, int func)
 	    showlimits(hard, lim);
 	    return 0;
 	}
-	if (lim==RLIMIT_CPU) {
+	if (limtype[lim] == ZLIMTYPE_TIME) {
 	    /* time-type resource -- may be specified as seconds, or minutes or *
 	     * hours with the `m' and `h' modifiers, and `:' may be used to add *
 	     * together more than one of these.  It's easier to understand from *
@@ -315,20 +315,11 @@ bin_limit(char *nam, char **argv, char *ops, int func)
 		    return 1;
 		}
 	    }
-	}
-# ifdef RLIMIT_NPROC
-	else if (lim == RLIMIT_NPROC)
-	    /* pure numeric resource -- only a straight decimal number is
-	    permitted. */
-	    val = zstrtorlimt(s, &s, 10);
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_NOFILE
-	else if (lim == RLIMIT_NOFILE)
+	} else if (limtype[lim] == ZLIMTYPE_NUMBER || limtype[lim] == ZLIMTYPE_UNKNOWN) {
 	    /* pure numeric resource -- only a straight decimal number is
 	    permitted. */
 	    val = zstrtorlimt(s, &s, 10);
-# endif /* RLIMIT_NOFILE */
-	else {
+	} else {
 	    /* memory-type resource -- `k' and `M' modifiers are permitted,
 	    meaning (respectively) 2^10 and 2^20. */
 	    val = zstrtorlimt(s, &s, 10);