Work on `id`. Still missing some functionality.
[lab.git] / sleep.c
blob5a8ce631cd78063d9ddbe9adfd093c56bd4a1ece
1 /* `sleep.c` - suspend execution for an interval
2 Copyright (c) 2022, Alan Potteiger
3 See `LICENSE` for copyright and license details */
5 #define _POSIX_C_SOURCE 200809L
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <errno.h>
10 #include <unistd.h>
12 static const char *usage = {
13 "usage: sleep time\n"
16 /* this is the first utility cause I'm tired as hell */
18 int
19 main(int argc, char *argv[])
21 long sec;
23 if (argc < 2) {
24 fputs(usage, stderr);
25 return 1;
28 sec = strtol(argv[1], NULL, 10);
29 if (sec == 0 && errno == EINVAL) {
30 perror("sleep");
31 fputs(usage, stderr);
32 return 1;
35 sleep((unsigned int) sec);
37 return 0;