annotate toys/posix/sleep.c @ 1776:7bf68329eb3b draft default tip

Repository switched to git at https://github.com/landley/toybox
author Rob Landley <rob@landley.net>
date Thu, 09 Apr 2015 02:28:32 -0500
parents ce0519f6457c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* sleep.c - Wait for a number of seconds.
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
2 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
3 * Copyright 2007 Rob Landley <rob@landley.net>
515
a057cbaeaf16 Add fraction and extension support to sleep.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents: 237
diff changeset
4 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
5 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
6 * See http://opengroup.org/onlinepubs/9699919799/utilities/sleep.html
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
7
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
8 USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
9
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
10 config SLEEP
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
11 bool "sleep"
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
12 default y
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
13 help
952
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
14 usage: sleep LENGTH
516
ec7dd0ef7eae Make floating point support depend on TOYBOX_FLOAT, make 0.1m work.
Rob Landley <rob@landley.net>
parents: 515
diff changeset
15
952
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
16 Wait before exiting. An optional suffix can be "m" (minutes), "h" (hours),
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
17 "d" (days), or "s" (seconds, the default).
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
18
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
19
516
ec7dd0ef7eae Make floating point support depend on TOYBOX_FLOAT, make 0.1m work.
Rob Landley <rob@landley.net>
parents: 515
diff changeset
20 config SLEEP_FLOAT
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
21 bool
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
22 default y
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
23 depends on SLEEP && TOYBOX_FLOAT
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.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
24 help
952
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
25 Length can be a decimal fraction.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 198
diff changeset
26 */
118
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents:
diff changeset
27
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 #include "toys.h"
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents:
diff changeset
29
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 118
diff changeset
30 void sleep_main(void)
118
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 {
952
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
32 struct timespec tv;
516
ec7dd0ef7eae Make floating point support depend on TOYBOX_FLOAT, make 0.1m work.
Rob Landley <rob@landley.net>
parents: 515
diff changeset
33
952
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
34 tv.tv_sec = xparsetime(*toys.optargs, 1000000000, &tv.tv_nsec);
ce0519f6457c Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
35 toys.exitval = !!nanosleep(&tv, NULL);
118
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 }