bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

sleep.c (517B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void
sig_handler(int sig) {
    (void)sig;
    exit(0);
}

int
main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "usage: %s time\n", *argv);
        return 1;
    }

    signal(SIGALRM, sig_handler);

    errno = 0;
    unsigned long t = strtoul(argv[1], NULL, 10);
    if (errno || t == ULONG_MAX)
        return 1;
    while (t > 0)
        t = sleep(t);
    return 0;
}