diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 03:20:17 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 03:20:17 -0400 |
| commit | fc98d05ef934e7a52161182ca5c55d7b23174012 (patch) | |
| tree | 8839c3634576fe2f7eb1c0ba6ef31ba5051f6aae /builtins | |
| parent | 790bbab30374f6317ebbc1e6be6a94236e11e370 (diff) | |
Add sleep()
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/functions.c | 9 | ||||
| -rw-r--r-- | builtins/functions.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index 5b019106..3c01f678 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <sys/param.h> #include <sys/random.h> +#include <time.h> #include <uninorm.h> #include <unistd.h> @@ -370,4 +371,12 @@ public bool pop_flag(char **argv, int *i, const char *flag, Text_t *result) } } +public void sleep_num(double seconds) +{ + struct timespec ts; + ts.tv_sec = (time_t)seconds; + ts.tv_nsec = (long)((seconds - (double)ts.tv_sec) * 1e9); + nanosleep(&ts, NULL); +} + // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/functions.h b/builtins/functions.h index 550676b4..b79c596a 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -33,5 +33,6 @@ int generic_print(const void *obj, bool colorize, const TypeInfo *type); Closure_t spawn(Closure_t fn); bool pop_flag(char **argv, int *i, const char *flag, Text_t *result); void print_stack_trace(FILE *out, int start, int stop); +void sleep_num(double seconds); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
