26 lines
558 B
C
26 lines
558 B
C
#include <errno.h> /* errno */
|
|
#include <stdio.h> /* fprintf(3), stderr */
|
|
#include <stdlib.h> /* strtol(3) */
|
|
#include <sysexits.h> /* EX_USAGE */
|
|
#include <unistd.h> /* sleep(3) */
|
|
|
|
static char *program_name = "sleep";
|
|
|
|
int main(int argc, char **argv){
|
|
int s;
|
|
extern int errno;
|
|
|
|
if(argc != 2){
|
|
usage: fprintf(stderr, "Usage: %s [seconds]\n",
|
|
argv[0] == NULL ? program_name : argv[0]);
|
|
return EX_USAGE;
|
|
}
|
|
errno = 0;
|
|
s = strtol(argv[1], &argv[1], 10);
|
|
if(*argv[1] != '\0' || errno != 0)
|
|
goto usage;
|
|
while(s > 0)
|
|
s = sleep(s);
|
|
return s;
|
|
}
|