Date: Tue, 17 Feb 2015 16:01:01 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278905 - head/lib/libc/gen Message-ID: <201502171601.t1HG11pU089337@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Tue Feb 17 16:01:00 2015 New Revision: 278905 URL: https://svnweb.freebsd.org/changeset/base/278905 Log: ulimit(3): simplify. rlim_t is at least as large as long, so we don't need the extra variable to keep the intermediate step. We don't need the volatile either. The code was tested on i386 and amd64. Suggested by: bde X-MFC with: r278803 Modified: head/lib/libc/gen/ulimit.c Modified: head/lib/libc/gen/ulimit.c ============================================================================== --- head/lib/libc/gen/ulimit.c Tue Feb 17 15:19:58 2015 (r278904) +++ head/lib/libc/gen/ulimit.c Tue Feb 17 16:01:00 2015 (r278905) @@ -33,7 +33,6 @@ #include <errno.h> #include <limits.h> #include <stdarg.h> -#include <stdint.h> #include <ulimit.h> long @@ -41,8 +40,7 @@ ulimit(int cmd, ...) { struct rlimit limit; va_list ap; - volatile intmax_t targ; - long arg; + rlim_t arg; if (cmd == UL_GETFSIZE) { if (getrlimit(RLIMIT_FSIZE, &limit) == -1) @@ -53,18 +51,18 @@ ulimit(int cmd, ...) return ((long)limit.rlim_cur); } else if (cmd == UL_SETFSIZE) { va_start(ap, cmd); - targ = arg = va_arg(ap, long); + arg = va_arg(ap, long); va_end(ap); - if (targ < 0) - targ = LONG_MAX; - if (targ > RLIM_INFINITY / 512) - targ = RLIM_INFINITY / 512; - limit.rlim_max = limit.rlim_cur = targ * 512; + if (arg < 0) + arg = LONG_MAX; + if (arg > RLIM_INFINITY / 512) + arg = RLIM_INFINITY / 512; + limit.rlim_max = limit.rlim_cur = arg * 512; /* The setrlimit() function sets errno to EPERM if needed. */ if (setrlimit(RLIMIT_FSIZE, &limit) == -1) return (-1); - return ((long)targ); + return ((long)arg); } else { errno = EINVAL; return (-1);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502171601.t1HG11pU089337>