summaryrefslogtreecommitdiff
path: root/lib/sleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sleep.c')
-rw-r--r--lib/sleep.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/sleep.c b/lib/sleep.c
new file mode 100644
index 0000000..f016a9e
--- /dev/null
+++ b/lib/sleep.c
@@ -0,0 +1,30 @@
+#include "../include/sane/config.h"
+
+#ifndef HAVE_SLEEP
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+unsigned int sleep(unsigned int seconds)
+{
+#ifdef HAVE_WINDOWS_H
+ Sleep(seconds*1000);
+ return 0;
+#else
+ int rc = 0;
+
+ /* WARNING: Not all platforms support usleep() for more than 1
+ * second. Assuming if they do not have POSIX sleep then they
+ * do not have POSIX usleep() either and are using our internal
+ * version which can support it. If it fails, need to add an OS
+ * specific replacement like Sleep for Windows.
+ */
+ if (usleep(seconds*1000000))
+ rc = 1;
+ return rc;
+#endif
+
+}
+
+#endif