1
0

no longer reliant on libio

This commit is contained in:
dtb 2023-08-19 11:02:19 -04:00
parent 03b51b7b9b
commit 38b4853cf5
2 changed files with 16 additions and 9 deletions

7
sleep/Makefile Normal file
View File

@ -0,0 +1,7 @@
sleep: sleep.c
$(CC) -g -o sleep sleep.c
clean:
rm -f sleep
.PHONY: clean

View File

@ -1,23 +1,23 @@
#include <ctype.h> /* isdigit(3) */ #include <ctype.h> /* isdigit(3) */
#include <stdlib.h> /* atoi(3) */ #include <errno.h> /* errno */
#include <stdio.h> /* fprintf(3), stderr */
#include <stdlib.h> /* strtol(3) */
#include <sysexits.h> /* EX_USAGE */ #include <sysexits.h> /* EX_USAGE */
#include <unistd.h> /* sleep(3) */ #include <unistd.h> /* sleep(3) */
#include "libio.h"
static char *program_name = "sleep"; static char *program_name = "sleep";
int main(int argc, char **argv){ int main(int argc, char **argv){
int s; int s;
extern int errno;
if(argc != 2){ if(argc != 2){
usage: write(2, "Usage: ", 7); usage: fprintf(stderr, "Usage: %s [seconds]\n", argv[0] == NULL ? program_name : argv[0]);
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
write(2, " [seconds]\n", 11);
return EX_USAGE; return EX_USAGE;
} }
s = parse_uint(argv[1]); errno = 0;
while(isdigit(*argv[1])) s = strtol(argv[1], &argv[1], 10);
++argv[1]; if(*argv[1] != '\0' || errno != 0)
if(*argv[1] != '\0')
goto usage; goto usage;
while(s > 0) while(s > 0)
s = sleep(s); s = sleep(s);