00001 /* 00002 alarm example 00003 AUP2, Sec. 8.07.1 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 /*[pgm]*/ 00023 static void handler(int signum) 00024 { 00025 } 00026 00027 int main(void) 00028 { 00029 struct sigaction act; 00030 char buf[100]; 00031 ssize_t rtn; 00032 00033 memset(&act, 0, sizeof(act)); 00034 act.sa_handler = handler; 00035 ec_neg1( sigaction(SIGALRM, &act, NULL) ) 00036 alarm(5); 00037 if ((rtn = read(STDIN_FILENO, buf, sizeof(buf) - 1)) == -1) { 00038 if (errno == EINTR) 00039 printf("Timed out... type faster next time!\n"); 00040 else 00041 EC_FAIL 00042 } 00043 alarm(0); 00044 if (rtn == 0) 00045 printf("Got EOF\n"); 00046 else if (rtn > 0) { 00047 buf[rtn] = '\0'; 00048 printf("Got %s", buf); 00049 } 00050 exit(EXIT_SUCCESS); 00051 00052 EC_CLEANUP_BGN 00053 exit(EXIT_FAILURE); 00054 EC_CLEANUP_END 00055 }