00001 /* 00002 sleep implementation using alarm (naive) 00003 AUP2, Sec. 9.07.2 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 // assumes no other use of alarm 00023 /*[pgm]*/ 00024 static void slp_handler(int signum) 00025 { 00026 } 00027 00028 unsigned aup_sleep(unsigned secs) 00029 { 00030 struct sigaction act; 00031 unsigned unslept; 00032 00033 memset(&act, 0, sizeof(act)); 00034 act.sa_handler = slp_handler; 00035 ec_neg1( sigaction(SIGALRM, &act, NULL) ) 00036 alarm(secs); 00037 pause(); 00038 unslept = alarm(0); 00039 return unslept; 00040 00041 EC_CLEANUP_BGN 00042 EC_FLUSH("aup_sleep") 00043 return 0; 00044 EC_CLEANUP_END 00045 } 00046 /*[]*/ 00047 int main(void) 00048 { 00049 time_t tm; 00050 00051 time(&tm); 00052 printf("Test 1 -- time %ld\n", (long)tm); 00053 aup_sleep(6); 00054 time(&tm); 00055 printf("Exiting -- time %ld\n", (long)tm); 00056 exit(EXIT_SUCCESS); 00057 }