summary refs log tree commit diff
path: root/sysdeps/unix/bsd/ulimit.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/bsd/ulimit.c')
-rw-r--r--sysdeps/unix/bsd/ulimit.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/sysdeps/unix/bsd/ulimit.c b/sysdeps/unix/bsd/ulimit.c
index b25a58314d..4a242efe1c 100644
--- a/sysdeps/unix/bsd/ulimit.c
+++ b/sysdeps/unix/bsd/ulimit.c
@@ -16,10 +16,11 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+#include <errno.h>
+#include <stdarg.h>
 #include <sysdep.h>
-#include <sys/resource.h>
 #include <unistd.h>
-#include <errno.h>
+#include <sys/resource.h>
 
 #ifndef	 HAVE_GNU_LD
 #define	 _etext	etext
@@ -36,51 +37,50 @@ extern int _etext;
        can open.
    Returns -1 on errors.  */
 long int
-ulimit (cmd, newlimit)
-     int cmd;
-     long int newlimit;
+ulimit (int cmd, ...)
 {
-  int status;
+  struct rlimit limit;
+  va_list va;
+  long int result = -1;
+
+  va_start (va, cmd);
 
   switch (cmd)
     {
-    case 1:
-      {
-	/* Get limit on file size.  */
-	struct rlimit fsize;
-
-	status = getrlimit (RLIMIT_FSIZE, &fsize);
-	if (status < 0)
-	  return -1;
-
+    case UL_GETFSIZE:
+      /* Get limit on file size.  */
+      if (getrlimit (RLIMIT_FSIZE, &limit) == 0)
 	/* Convert from bytes to 512 byte units.  */
-	return fsize.rlim_cur / 512;
-      }
-    case 2:
+	result = limit.rlim_cur / 512;
+      break;
+
+    case UL_SETFSIZE:
       /* Set limit on file size.  */
       {
-	struct rlimit fsize;
-	fsize.rlim_cur = newlimit * 512;
-	fsize.rlim_max = newlimit * 512;
+	long int newlimit = va_arg (va, long int);
+
+	limit.rlim_cur = newlimit * 512;
+	limit.rlim_max = newlimit * 512;
 
-	return setrlimit (RLIMIT_FSIZE, &fsize);
+	result = setrlimit (RLIMIT_FSIZE, &limit);
       }
-    case 3:
-      /* Get maximum address for `brk'.  */
-      {
-	struct rlimit dsize;
+      break;
 
-	status = getrlimit (RLIMIT_DATA, &dsize);
-	if (status < 0)
-	  return -1;
+    case __UL_GETMAXBRK:
+      /* Get maximum address for `brk'.  */
+      if (getrlimit (RLIMIT_DATA, &limit) == 0)
+	result = ((long int) &_etext) + limit.rlim_cur;
+      break;
 
-	return ((long int) &_etext) + dsize.rlim_cur;
-      }
-    case 4:
-      return sysconf (_SC_OPEN_MAX);
+    case __UL_GETOPENMAX:
+      result = sysconf (_SC_OPEN_MAX);
+      break;
 
     default:
       __set_errno (EINVAL);
-      return -1;
     }
+
+  va_end (va);
+
+  return result;
 }