home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / zmodem.t.Z / zmodem.t / alarmread.c next >
C/C++ Source or Header  |  1988-06-13  |  1KB  |  61 lines

  1. #include <time.h>
  2.  
  3. int alarmread(fd,buffer,count,function,timeout)
  4.     register int fd;
  5.     register char *buffer;
  6.     int count;
  7.     int (*function)();
  8.     register int timeout;
  9. {
  10.     register unsigned int i;
  11.     register int n;
  12.     static int ticksec = 0;
  13.     if(ticksec == 0) ticksec = CLK_TCK;
  14.  
  15.     timeout = timeout * (ticksec + 1);    /* at least one second of sleep */
  16.     while( ((n=_gs_rdy(fd)) <= 0) && (--timeout != 0) )
  17.     {
  18.         tsleep(2);        /* give at least one time slice */
  19.     }
  20.     if( timeout != 0)
  21.         return( read(fd,buffer, (count >= n) ? n : count) );
  22.     return((*function)());
  23. }
  24. #include    <direct.h>
  25.  
  26. utime (file, timep)
  27. char    *file;
  28. time_t    timep[2];
  29. {
  30.     struct tm    *localtime ();
  31.     struct tm    *tbuf;
  32.     int    fd;
  33.     struct fildes    buf;
  34.     
  35.     if ((fd = open (file, 0)) < 0)
  36.         return -1;
  37.         
  38.     if (_gs_gfd (fd, &buf, sizeof (struct fildes)) < 0)
  39.     {
  40.         close (fd);
  41.         return -1;
  42.     }
  43.     
  44.     tbuf = localtime (&(timep[1]));
  45.     sprintf (buf.fd_date, "%c%c%c%c%c",
  46.         (char) tbuf->tm_year,
  47.         (char) tbuf->tm_mon,
  48.         (char) tbuf->tm_mday,
  49.         (char) tbuf->tm_hour,
  50.         (char) tbuf->tm_min );
  51.     
  52.     if (_ss_pfd (fd, &buf) < 0)
  53.     {
  54.         close (fd);
  55.         return -1;
  56.     }
  57.     
  58.     close (fd);
  59.     return 0;
  60. }
  61.