sleep.c 841 B

12345678910111213141516171819202122232425262728293031323334
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9. #define REQ_PRINT_USAGE /* Require print_usage() from ../common/common.h */
  10. #define REQ_ERRPRINT /* Require errprint() from ../common/common.h */
  11. #define DESCRIPTION "Suspend execution for an interval."
  12. #define OPERANDS "time"
  13. #include "../common/common.h"
  14. int main(int argc, char *argv[]) {
  15. long unsigned int seconds;
  16. if (argc == 2) {
  17. seconds = strtol(argv[1], NULL, 10);
  18. if (!seconds) {
  19. print_usage(argv[0], DESCRIPTION, OPERANDS, VERSION);
  20. return 1;
  21. }
  22. sleep(seconds);
  23. }
  24. else if (argc == 1) {
  25. print_usage(argv[0], DESCRIPTION, OPERANDS, VERSION);
  26. return 1;
  27. }
  28. return errprint(argv[0], NULL, errno);
  29. }