home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DELAY.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  56 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  DELAY.C - A portable time delay compatible with Borland's and Watcom's
  5. **            delay() function.
  6. **
  7. **  public domain demo by Bob Stout
  8. */
  9.  
  10. #if (!defined(__WATCOMC__) && !defined(__TURBOC__)) || (defined(__TURBOC__) \
  11.       && (defined(_Windows) && !defined(__DPMI16) && !defined(__DPMI32__)))
  12.  
  13. #include <time.h>
  14. #include "delay.h"
  15.  
  16. #ifndef  CLOCKS_PER_SEC                   /* CLOCKS_PER_SEC is ANSI/ISO */
  17.  #define CLOCKS_PER_SEC CLK_TCK
  18. #endif
  19.  
  20. void delay(unsigned short msec)
  21. {
  22.       clock_t t0;
  23.       unsigned long diff = 0L;
  24.  
  25.       for (t0 = clock(); diff < (unsigned long)msec; )
  26.       {
  27.             diff  = (unsigned long)(clock() - t0);
  28.             diff *= 1000L;
  29.             diff /= CLOCKS_PER_SEC;
  30.       }
  31. }
  32.  
  33. #ifdef TEST
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37.  
  38. main(int argc, char *argv[])
  39. {
  40.       int msec;
  41.  
  42.       if (2 > argc)
  43.       {
  44.             puts("Usage: DELAY milliseconds");
  45.             return EXIT_FAILURE;
  46.       }
  47.       msec = atoi(argv[1]);
  48.       printf("Delaying %d milliseconds\n", msec);
  49.       delay(msec);
  50.       return EXIT_SUCCESS;
  51. }
  52.  
  53. #endif /* TEST */
  54.  
  55. #endif /* Not Watcom or Borland */
  56.