mp-utils/src/sleep.c

44 lines
723 B
C

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <ctype.h>
#include "support.h"
int main(int argc, char **argv)
{
int i;
i = 0;
if(argc != 2)
{
throw(NEEDARG_FAIL, mastrcat(argv[0], " int"));
}
/* have we received a positive integer? */
/* subtract one from strlen result to account for zero indexing */
for(i = (strlen(argv[1])-1); i >= 0; i--)
{
if(!isdigit(argv[1][i]))
{
throw(NEEDARG_FAIL, mastrcat(argv[0], " int"));
}
}
i = (int) (strtol(argv[1], (char **) NULL, 10));
if(errno == ERANGE)
{
throw(TIME_FAIL, mastrcat(argv[0], " ERANGE error."));
}
sleep(i);
exit(EXIT_SUCCESS);
}