use libio
This commit is contained in:
parent
4eb64cdc5a
commit
0f7c7985ba
22
src/sleep.c
22
src/sleep.c
@ -1,20 +1,26 @@
|
|||||||
|
#include <ctype.h> /* isdigit(3) */
|
||||||
#include <stdlib.h> /* atoi(3) */
|
#include <stdlib.h> /* atoi(3) */
|
||||||
#include <sysexits.h> /* EX_USAGE */
|
#include <sysexits.h> /* EX_USAGE */
|
||||||
#include <unistd.h> /* sleep(3) */
|
#include <unistd.h> /* sleep(3) */
|
||||||
#include "libstris.h" /* stris(3) */
|
#include "libio.h"
|
||||||
#include "noargvzero.h"
|
|
||||||
|
static char *program_name = "sleep";
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int s;
|
int s;
|
||||||
NOARGVZERO(argv);
|
if(argc != 2){
|
||||||
if(argc != 2 || !stris(STRIS_TYPE_INT, argv[1])){
|
usage: write(2, "Usage: ", 7);
|
||||||
write(2, "Usage: ", 7);
|
if(argv[0] == NULL)
|
||||||
for(s = 0; argv[0][s] != '\0'; ++s);
|
argv[0] = program_name;
|
||||||
write(2, argv[0], s);
|
fdprint(2, argv[0]);
|
||||||
write(2, " [seconds]\n", 11);
|
write(2, " [seconds]\n", 11);
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
s = atoi(argv[1]);
|
s = parse_uint(argv[1]);
|
||||||
|
while(isdigit(*argv[1]))
|
||||||
|
++argv[1];
|
||||||
|
if(*argv[1] != '\0')
|
||||||
|
goto usage;
|
||||||
while(s > 0)
|
while(s > 0)
|
||||||
s = sleep(s);
|
s = sleep(s);
|
||||||
return s;
|
return s;
|
||||||
|
Loading…
Reference in New Issue
Block a user