comparison toys/posix/sleep.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 6df4ccc0acbe
children ce0519f6457c
comparison
equal deleted inserted replaced
693:4a5a250e0633 694:786841fdb1e0
1 /* vi: set sw=4 ts=4: 1 /* sleep.c - Wait for a number of seconds.
2 *
3 * sleep.c - Wait for a number of seconds.
4 * 2 *
5 * Copyright 2007 Rob Landley <rob@landley.net> 3 * Copyright 2007 Rob Landley <rob@landley.net>
6 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> 4 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
7 * 5 *
8 * See http://opengroup.org/onlinepubs/9699919799/utilities/sleep.html 6 * See http://opengroup.org/onlinepubs/9699919799/utilities/sleep.html
9 7
10 USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN)) 8 USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
11 9
12 config SLEEP 10 config SLEEP
13 bool "sleep" 11 bool "sleep"
14 default y 12 default y
15 help 13 help
16 usage: sleep SECONDS 14 usage: sleep SECONDS
17 15
18 Wait before exiting. 16 Wait before exiting.
19 17
20 config SLEEP_FLOAT 18 config SLEEP_FLOAT
21 bool 19 bool
22 default y 20 default y
23 depends on SLEEP && TOYBOX_FLOAT 21 depends on SLEEP && TOYBOX_FLOAT
24 help 22 help
25 The delay can be a decimal fraction. An optional suffix can be "m" 23 The delay can be a decimal fraction. An optional suffix can be "m"
26 (minutes), "h" (hours), "d" (days), or "s" (seconds, the default). 24 (minutes), "h" (hours), "d" (days), or "s" (seconds, the default).
27 */ 25 */
28 26
29 #include "toys.h" 27 #include "toys.h"
30 28
31 void sleep_main(void) 29 void sleep_main(void)
32 { 30 {
33 31
34 if (!CFG_TOYBOX_FLOAT) toys.exitval = sleep(atol(*toys.optargs)); 32 if (!CFG_TOYBOX_FLOAT) toys.exitval = sleep(atol(*toys.optargs));
35 else { 33 else {
36 char *arg; 34 char *arg;
37 double d = strtod(*toys.optargs, &arg); 35 double d = strtod(*toys.optargs, &arg);
38 struct timespec tv; 36 struct timespec tv;
39 37
40 // Parse suffix 38 // Parse suffix
41 if (*arg) { 39 if (*arg) {
42 int ismhd[]={1,60,3600,86400}; 40 int ismhd[]={1,60,3600,86400};
43 char *smhd = "smhd", *c = strchr(smhd, *arg); 41 char *smhd = "smhd", *c = strchr(smhd, *arg);
44 if (!c) error_exit("Unknown suffix '%c'", *arg); 42 if (!c) error_exit("Unknown suffix '%c'", *arg);
45 d *= ismhd[c-smhd]; 43 d *= ismhd[c-smhd];
46 } 44 }
47 45
48 tv.tv_nsec=1000000000*(d-(tv.tv_sec = (unsigned long)d)); 46 tv.tv_nsec=1000000000*(d-(tv.tv_sec = (unsigned long)d));
49 toys.exitval = !!nanosleep(&tv, NULL); 47 toys.exitval = !!nanosleep(&tv, NULL);
50 } 48 }
51 } 49 }