26 lines
543 B
C
26 lines
543 B
C
#include <ctype.h> /* isdigit(3) */
|
|
#include <stdlib.h> /* atoi(3) */
|
|
#include <sysexits.h> /* EX_USAGE */
|
|
#include <unistd.h> /* sleep(3) */
|
|
#include "libio.h"
|
|
|
|
static char *program_name = "sleep";
|
|
|
|
int main(int argc, char **argv){
|
|
int s;
|
|
if(argc != 2){
|
|
usage: write(2, "Usage: ", 7);
|
|
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
|
write(2, " [seconds]\n", 11);
|
|
return EX_USAGE;
|
|
}
|
|
s = parse_uint(argv[1]);
|
|
while(isdigit(*argv[1]))
|
|
++argv[1];
|
|
if(*argv[1] != '\0')
|
|
goto usage;
|
|
while(s > 0)
|
|
s = sleep(s);
|
|
return s;
|
|
}
|