summaryrefslogtreecommitdiffstats
path: root/libblkid/include/timer.h
diff options
context:
space:
mode:
authorbigbiff <bigbiff@teamw.in>2015-01-02 01:44:14 +0100
committerDees Troy <dees_troy@teamw.in>2015-01-05 04:38:42 +0100
commit7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de (patch)
treefb69cb515cb4ab675d5850684cc402100b7a2a22 /libblkid/include/timer.h
parentcrypto: remove unused libs and clean up makefile (diff)
downloadandroid_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar.gz
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar.bz2
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar.lz
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar.xz
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.tar.zst
android_bootable_recovery-7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de.zip
Diffstat (limited to 'libblkid/include/timer.h')
-rw-r--r--libblkid/include/timer.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/libblkid/include/timer.h b/libblkid/include/timer.h
new file mode 100644
index 000000000..79ef64919
--- /dev/null
+++ b/libblkid/include/timer.h
@@ -0,0 +1,31 @@
+#ifndef UTIL_LINUX_TIMER_H
+#define UTIL_LINUX_TIMER_H
+
+#include <signal.h>
+#include <sys/time.h>
+
+static inline int setup_timer(
+ struct itimerval *timer,
+ struct itimerval *old_timer,
+ struct sigaction *old_sa,
+ void (*timeout_handler)(int))
+{
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof sa);
+ sa.sa_handler = timeout_handler;
+ sa.sa_flags = SA_RESETHAND;
+ sigaction(SIGALRM, &sa, old_sa);
+
+ return setitimer(ITIMER_REAL, timer, old_timer);
+}
+
+static inline void cancel_timer(
+ struct itimerval *old_timer,
+ struct sigaction *old_sa)
+{
+ setitimer(ITIMER_REAL, old_timer, NULL);
+ sigaction(SIGALRM, old_sa, NULL);
+}
+
+#endif