diff options
author | pfg <pfg@FreeBSD.org> | 2015-02-17 16:01:00 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-02-17 16:01:00 +0000 |
commit | 3f44c8b9f32b9c7540d172f7c4d417b3b45daebe (patch) | |
tree | b858b79a33463473934bb087ccc907a5fce104ab | |
parent | a86377a7d01dfcfb77f8143e978090043e18a3e3 (diff) | |
download | FreeBSD-src-3f44c8b9f32b9c7540d172f7c4d417b3b45daebe.zip FreeBSD-src-3f44c8b9f32b9c7540d172f7c4d417b3b45daebe.tar.gz |
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
-rw-r--r-- | lib/libc/gen/ulimit.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/libc/gen/ulimit.c b/lib/libc/gen/ulimit.c index db1d498..2c090c0 100644 --- a/lib/libc/gen/ulimit.c +++ b/lib/libc/gen/ulimit.c @@ -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); |