diff options
Diffstat (limited to 'sleep.c')
-rw-r--r-- | sleep.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com> + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> + +#define REQ_PRINT_USAGE /* Require print_usage() from common.h */ +#define REQ_ERRPRINT /* Require errprint() from common.h */ +#define DESCRIPTION "Suspend execution for an interval." +#define OPERANDS "time" +#include "common.h" + +#ifdef FASESBOX +int sleep_main(int argc, char *argv[]) { +#else +int main(int argc, char *argv[]) { +#endif + long unsigned int seconds; + + if (argc == 2) { + seconds = strtol(argv[1], NULL, 10); + if (!seconds) { + print_usage(argv[0], DESCRIPTION, OPERANDS, VERSION); + return 1; + } + sleep(seconds); + } + else if (argc == 1) { + print_usage(argv[0], DESCRIPTION, OPERANDS, VERSION); + return 1; + } + + return errprint(argv[0], NULL, errno); +} |