blob: 6060e73e7e8371e7df12b7fb66853d5241342aab (
plain)
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
|
#include "stddef.h"
#include <err.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char **argv)
{
double seconds;
struct timespec ts;
if (argc != 2) {
write(1, "usage: sleep seconds\n", 21);
return 0;
}
seconds = strtod(argv[1], NULL);
ts.tv_sec = (time_t)seconds;
ts.tv_nsec = (long)((seconds - (double)ts.tv_sec) * 1e9);
if (nanosleep(&ts, NULL) < 0)
err(1, "nanosleep");
return 0;
}
|