home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / stg_v4.lzh / get_key.c < prev    next >
C/C++ Source or Header  |  1994-11-11  |  662b  |  47 lines

  1. /*
  2.  * get_key() - returns -1 if timeout or char
  3. */
  4. #include "stglib.h"
  5.  
  6. #define TIME_RES 10
  7. #define TIME_OUT _time_out
  8.  
  9. extern int _time_out;
  10.  
  11. get_key()
  12. {
  13.     int to;
  14.     char c;
  15.  
  16.     to=TIME_OUT*TIME_RES;
  17.  
  18. /*    if (getuid()<=15)
  19.         to=-1;
  20. */
  21.     signal(SIGINT,SIG_IGN);
  22.     signal(SIGQUIT,SIG_IGN);
  23.     _ss_mode(2,3);
  24.  
  25.     while (to--)
  26.     {
  27.         if (_gs_rdy(2)==ERR /* && errno==246 */ )
  28.         {
  29.             usleep(1000000/TIME_RES);
  30.             continue;
  31.         }
  32.  
  33.         if (read(2,&c,1)==1)
  34.         {
  35.             _ss_mode(2,0);
  36.             signal(SIGINT,SIG_DFL);
  37.             signal(SIGQUIT,SIG_DFL);
  38.             return(c);
  39.         }
  40.     }
  41.     _ss_mode(2,0);
  42.     signal(SIGINT,SIG_DFL);
  43.     signal(SIGQUIT,SIG_DFL);
  44.     return(ERR);
  45. }
  46.  
  47.