no longer reliant on libio
This commit is contained in:
parent
03b51b7b9b
commit
38b4853cf5
7
sleep/Makefile
Normal file
7
sleep/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
sleep: sleep.c
|
||||
$(CC) -g -o sleep sleep.c
|
||||
|
||||
clean:
|
||||
rm -f sleep
|
||||
|
||||
.PHONY: clean
|
@ -1,23 +1,23 @@
|
||||
#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 <unistd.h> /* sleep(3) */
|
||||
#include "libio.h"
|
||||
|
||||
static char *program_name = "sleep";
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int s;
|
||||
extern int errno;
|
||||
|
||||
if(argc != 2){
|
||||
usage: write(2, "Usage: ", 7);
|
||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
||||
write(2, " [seconds]\n", 11);
|
||||
usage: fprintf(stderr, "Usage: %s [seconds]\n", argv[0] == NULL ? program_name : argv[0]);
|
||||
return EX_USAGE;
|
||||
}
|
||||
s = parse_uint(argv[1]);
|
||||
while(isdigit(*argv[1]))
|
||||
++argv[1];
|
||||
if(*argv[1] != '\0')
|
||||
errno = 0;
|
||||
s = strtol(argv[1], &argv[1], 10);
|
||||
if(*argv[1] != '\0' || errno != 0)
|
||||
goto usage;
|
||||
while(s > 0)
|
||||
s = sleep(s);
|
||||
|
Loading…
Reference in New Issue
Block a user