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 31 32 33 34 35 36 37 38 39 40 41
|
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "parsenum.h"
#include "warnp.h"
int
main(int argc, char * argv[])
{
int msec;
struct timespec ts;
WARNP_INIT;
/* Parse command line. */
if (argc != 2) {
fprintf(stderr, "usage: %s milliseconds\n", argv[0]);
goto err0;
}
if (PARSENUM(&msec, argv[1], 0, INT_MAX)) {
warnp("PARSNEUM");
goto err0;
}
/* Sleep for the desired time. */
ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;
if (nanosleep(&ts, NULL)) {
warnp("nanosleep");
goto err0;
}
/* Success! */
exit(0);
err0:
/* Failure! */
exit(1);
}
|