diff options
author | Kiyoshi Aman <kiyoshi.aman+adelie@gmail.com> | 2019-05-25 08:03:18 -0500 |
---|---|---|
committer | Kiyoshi Aman <kiyoshi.aman+adelie@gmail.com> | 2019-05-25 08:03:18 -0500 |
commit | b9ed9a2c260864ebcf5b5ccaed6b765760310262 (patch) | |
tree | 7c4f00dfa338b7758f9f48467497ff9a9436bd69 /bin/sleep/sleep.c | |
parent | 874a49d1f54f5ad1ef005d4ff50f72a0a9738b86 (diff) | |
download | userland-b9ed9a2c260864ebcf5b5ccaed6b765760310262.tar.gz userland-b9ed9a2c260864ebcf5b5ccaed6b765760310262.tar.bz2 userland-b9ed9a2c260864ebcf5b5ccaed6b765760310262.tar.xz userland-b9ed9a2c260864ebcf5b5ccaed6b765760310262.zip |
bin/sleep: make buildable with libbsd, remove nonportable fractional extension
Diffstat (limited to 'bin/sleep/sleep.c')
-rw-r--r-- | bin/sleep/sleep.c | 86 |
1 files changed, 13 insertions, 73 deletions
diff --git a/bin/sleep/sleep.c b/bin/sleep/sleep.c index dfaf302..e8392e6 100644 --- a/bin/sleep/sleep.c +++ b/bin/sleep/sleep.c @@ -29,20 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94"; -#else -__RCSID("$NetBSD: sleep.c,v 1.29 2019/01/27 02:00:45 christos Exp $"); -#endif -#endif /* not lint */ - #include <ctype.h> #include <err.h> #include <locale.h> @@ -50,17 +36,18 @@ __RCSID("$NetBSD: sleep.c,v 1.29 2019/01/27 02:00:45 christos Exp $"); #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <bsd/stdlib.h> #include <time.h> #include <unistd.h> -__dead static void alarmhandle(int); -__dead static void usage(void); +static void alarmhandle(int); +static void usage(void); static void report(const time_t, const time_t, const char *const); static volatile sig_atomic_t report_requested; static void -report_request(int signo __unused) +report_request(int signo) { report_requested = 1; @@ -74,7 +61,7 @@ main(int argc, char *argv[]) double fval, ival, val; struct timespec ntime; time_t original; - int ch, fracflag; + int ch; unsigned delay; setprogname(argv[0]); @@ -93,66 +80,19 @@ main(int argc, char *argv[]) if (argc != 1) usage(); - /* - * Okay, why not just use atof for everything? Why bother - * checking if there is a fraction in use? Because the old - * sleep handled the full range of integers, that's why, and a - * double can't handle a large long. This is fairly useless - * given how large a number a double can hold on most - * machines, but now we won't ever have trouble. If you want - * 1000000000.9 seconds of sleep, well, that's your - * problem. Why use an isdigit() check instead of checking for - * a period? Because doing it this way means locales will be - * handled transparently by the atof code. - * - * Since fracflag is set for any non-digit, we also fall - * into the floating point conversion path if the input - * is hex (the 'x' in 0xA is not a digit). Then if - * strtod() handles hex (on NetBSD it does) so will we. - * That path is also taken for scientific notation (1.2e+3) - * and when the input is simply nonsense. - */ - fracflag = 0; arg = *argv; for (temp = arg; *temp != '\0'; temp++) if (!isdigit((unsigned char)*temp)) { - ch = *temp; - fracflag++; - } - - if (fracflag) { - /* - * If we cannot convert the value using the user's locale - * then try again using the C locale, so strtod() can always - * parse values like 2.5, even if the user's locale uses - * a different decimal radix character (like ',') - * - * (but only if that is the potential problem) - */ - val = strtod(arg, &temp); - if (*temp != '\0') - val = strtod_l(arg, &temp, LC_C_LOCALE); - if (val < 0 || temp == arg || *temp != '\0') usage(); + } - ival = floor(val); - fval = (1000000000 * (val-ival)); - ntime.tv_sec = ival; - if ((double)ntime.tv_sec != ival) - errx(1, "requested delay (%s) out of range", arg); - ntime.tv_nsec = fval; - - if (ntime.tv_sec == 0 && ntime.tv_nsec == 0) - return EXIT_SUCCESS; /* was 0.0 or underflowed */ - } else { - ntime.tv_sec = strtol(arg, &temp, 10); - if (ntime.tv_sec < 0 || temp == arg || *temp != '\0') - usage(); + ntime.tv_sec = strtol(arg, &temp, 10); + if (ntime.tv_sec < 0 || temp == arg || *temp != '\0') + usage(); - if (ntime.tv_sec == 0) - return EXIT_SUCCESS; - ntime.tv_nsec = 0; - } + if (ntime.tv_sec == 0) + return EXIT_SUCCESS; + ntime.tv_nsec = 0; original = ntime.tv_sec; if (ntime.tv_nsec != 0) @@ -160,7 +100,7 @@ main(int argc, char *argv[]) else msg = ""; - signal(SIGINFO, report_request); + signal(SIGHUP, report_request); if (ntime.tv_sec <= 10000) { /* arbitrary */ while (nanosleep(&ntime, &ntime) != 0) { |