1
0

use libio

This commit is contained in:
dtb 2022-06-14 17:06:13 -04:00
parent 4eb64cdc5a
commit 0f7c7985ba

View File

@ -1,20 +1,26 @@
#include <ctype.h> /* isdigit(3) */
#include <stdlib.h> /* atoi(3) */
#include <sysexits.h> /* EX_USAGE */
#include <unistd.h> /* sleep(3) */
#include "libstris.h" /* stris(3) */
#include "noargvzero.h"
#include "libio.h"
static char *program_name = "sleep";
int main(int argc, char **argv){
int s;
NOARGVZERO(argv);
if(argc != 2 || !stris(STRIS_TYPE_INT, argv[1])){
write(2, "Usage: ", 7);
for(s = 0; argv[0][s] != '\0'; ++s);
write(2, argv[0], s);
if(argc != 2){
usage: write(2, "Usage: ", 7);
if(argv[0] == NULL)
argv[0] = program_name;
fdprint(2, argv[0]);
write(2, " [seconds]\n", 11);
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)
s = sleep(s);
return s;