annotate lib/sleep.c @ 8786:b7c6961fb530

New module 'sleep'.
author Bruno Haible <bruno@clisp.org>
date Tue, 01 May 2007 22:15:01 +0000
parents
children bbbbbf4cd1c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8786
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Pausing execution of the current thread.
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <unistd.h>
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 # include <windows.h>
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 unsigned int
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 sleep (unsigned int seconds)
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 unsigned int remaining;
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 /* Sleep for 1 second many times, because
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 1. Sleep is not interruptiple by Ctrl-C,
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 2. we want to avoid arithmetic overflow while multiplying with 1000. */
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 for (remaining = seconds; remaining > 0; remaining--)
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 Sleep (1000);
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 return remaining;
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 }
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #else
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 #error "Please port gnulib sleep.c to your platform, possibly using usleep() or select(), then report this to bug-gnulib."
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
b7c6961fb530 New module 'sleep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #endif