3 * Copyright (C) 2002 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
22 * Example of a broken implementation for sleep
24 * Author: Simone Piccardi
27 ****************************************************************/
29 * Include needed headers
31 #include <unistd.h> /* unix standard library */
33 unsigned int sleep(unsigned int seconds)
36 * Variables definition
38 signandler_t prev_handler;
40 if ((prev_handler = signal(SIGALRM, alarm_hand)) == SIG_ERR) {
41 printf("Cannot set handler for alarm\n");
46 /* restore previous signal handler */
47 signal(SIGALRM, prev_handler);
48 /* remove alarm, return remaining time */
51 void alarm_hand(int sig) {
52 /* check if the signal is the right one */
53 if (sig != SIGALRM) { /* if not exit with error */
54 printf("Something wrong, handler for SIGALRM\n");
56 } else { /* do nothing, just interrupt pause */