From 0e21d3939c34fef1ac3d740ea9e8fc76a6550eaf Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 13 Oct 2023 19:33:48 +0300 Subject: [PATCH] sleep --- TODO | 15 +++++++++++++++ coreutils/sleep.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 TODO create mode 100644 coreutils/sleep.c diff --git a/TODO b/TODO new file mode 100644 index 0000000..9f4003e --- /dev/null +++ b/TODO @@ -0,0 +1,15 @@ +chmod +chown +printf +shuf +id +ln +cp +shred +du +df +dd +nice +nohup +mktemp +test diff --git a/coreutils/sleep.c b/coreutils/sleep.c new file mode 100644 index 0000000..e3aab2b --- /dev/null +++ b/coreutils/sleep.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +int main(const int argc, const char **argv) { + if (argc == 1) { + printf("sleep [num[m - minute / h - hour / d - days].. ] / [inf (infinity)]\n"); + return 0; + } + + if (!strcmp(argv[1], "inf")) + for (;;) + sleep(1); + + unsigned int sec = 0; + for (int i = 1; i < argc; i++) { + switch (argv[i][strlen(argv[i]) - 1]) { + case 'd': + sec += atoi(argv[i]) * 86400; + break; + + case 'h': + sec += atoi(argv[i]) * 3600; + break; + + case 'm': + sec += atoi(argv[i]) * 60; + break; + + default: + sec += atoi(argv[i]); + } + } + + sleep(sec); + return 0; +}