summaryrefslogtreecommitdiff
path: root/src/unistd/sleep.c
blob: 656f70f90d666a1385f1f3a4de1dae07eaddd6db (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 "sys/types.h"
#include <unistd.h>
#include "time.h"

#if _POSIX_C_SOURCE < 199309
#define nanosleep __nanosleep
#include "time/struct_timespec.c"
#include "time/nanosleep.c"
#endif

unsigned sleep(unsigned seconds)
{
	struct timespec tosleep = { seconds, 0 };
	struct timespec remaining = { 0 , 0 };

	if (nanosleep(&tosleep, &remaining) == -1) {
		return seconds;
	}

	return remaining.tv_sec;
}
/*
POSIX(1)
*/