diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-10-24 02:15:36 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-10-24 02:15:36 +0000 |
commit | 9ef3a9f8b2704693496af12120ea3ab40389bf7b (patch) | |
tree | 9ed582b049881f1271a6b02978f1ed6d28a4f948 /src/libstddjb/alarm_disable.c | |
parent | 422d91b2b0a2b8b3a8af510cc55b1400c60be303 (diff) | |
download | skalibs-9ef3a9f8b2704693496af12120ea3ab40389bf7b.tar.xz |
Add the alarm library, first draft.
Diffstat (limited to 'src/libstddjb/alarm_disable.c')
-rw-r--r-- | src/libstddjb/alarm_disable.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libstddjb/alarm_disable.c b/src/libstddjb/alarm_disable.c new file mode 100644 index 0000000..a383411 --- /dev/null +++ b/src/libstddjb/alarm_disable.c @@ -0,0 +1,41 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> +#include <skalibs/alarm.h> + +#ifdef SKALIBS_HASTIMER + +#include <time.h> +#include "alarm-internal.h" + +timer_t timer_here ; + +void alarm_disable () +{ + struct itimerspec stopit = { .it_value = { .tv_sec = 0, .tv_nsec = 0 }, .it_interval = { .tv_sec = 0, .tv_nsec = 0 } } ; + timer_settime(timer_here, 0, &stopit, 0) ; + timer_delete(timer_here) ; +} + +#else +#ifdef SKALIBS_HASITIMER + +#include <sys/time.h> + +void alarm_disable () +{ + struct itimerval stopit = { .it_value = { .tv_sec = 0, .tv_usec = 0 }, .it_interval = { .tv_sec = 0, .tv_usec = 0 } } ; + setitimer(ITIMER_REAL, &stopit, 0) ; +} + +#else + +#include <unistd.h> + +void alarm_disable () +{ + alarm(0) ; +} + +#endif +#endif |