improve of cmpl.
[bush.git] / examples / loadables / sleep.c
blobb0ec266323802e3dc33b0def3d06fb93a7907387
1 /*
2 * sleep -- sleep for fractions of a second
4 * usage: sleep seconds[.fraction]
5 */
7 /*
8 Copyright (C) 1999-2020 Free Software Foundation, Inc.
10 This file is part of GNU Bush.
11 Bush is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 Bush is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with Bush. If not, see <http://www.gnu.org/licenses/>.
25 #include "config.h"
27 #include "bushtypes.h"
29 #if defined (TIME_WITH_SYS_TIME)
30 # include <sys/time.h>
31 # include <time.h>
32 #else
33 # if defined (HAVE_SYS_TIME_H)
34 # include <sys/time.h>
35 # else
36 # include <time.h>
37 # endif
38 #endif
40 #if defined (HAVE_UNISTD_H)
41 #include <unistd.h>
42 #endif
44 #include <stdio.h>
45 #include "chartypes.h"
47 #include "shell.h"
48 #include "builtins.h"
49 #include "common.h"
51 int
52 sleep_builtin (list)
53 WORD_LIST *list;
55 long sec, usec;
56 char *ep;
57 int r, mul;
58 time_t t;
60 if (list == 0) {
61 builtin_usage();
62 return(EX_USAGE);
65 /* Skip over `--' */
66 if (list->word && ISOPTION (list->word->word, '-'))
67 list = list->next;
69 if (*list->word->word == '-' || list->next) {
70 builtin_usage ();
71 return (EX_USAGE);
74 r = uconvert(list->word->word, &sec, &usec, &ep);
75 /* Maybe postprocess conversion failures here based on EP */
77 if (r) {
78 fsleep(sec, usec);
79 QUIT;
80 return(EXECUTION_SUCCESS);
83 builtin_error("%s: bad sleep interval", list->word->word);
84 return (EXECUTION_FAILURE);
87 static char *sleep_doc[] = {
88 "Suspend execution for specified period.",
90 "sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.",
91 (char *)NULL
94 struct builtin sleep_struct = {
95 "sleep",
96 sleep_builtin,
97 BUILTIN_ENABLED,
98 sleep_doc,
99 "sleep seconds[.fraction]",