home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / toaster.zip / Compat / port.c < prev    next >
C/C++ Source or Header  |  1991-12-31  |  1KB  |  54 lines

  1. #include <sys/types.h>
  2. #include <sys/time.h>
  3.  
  4. #include "lint.h"
  5.  
  6. #ifdef sun
  7. time_t time PROT((time_t *));
  8. #endif
  9.  
  10.  
  11. /*
  12.  * This file defines things that may have to be changem when porting
  13.  * LPmud to new environments. Hopefully, there are #ifdef's that will take
  14.  * care of everything.
  15.  */
  16.  
  17. /*
  18.  * Return a random number in the range 0 .. n-1
  19.  */
  20. int random_number(n)
  21.     int n;
  22. {
  23. #ifdef RANDOM
  24.     return random() % n;
  25. #else /* RANDOM */
  26. #ifdef DRAND48
  27.     return (int)(drand48() * n);
  28. #else /* DRAND48 */
  29.     extern int current_time;
  30.  
  31.     return current_time % n;    /* Suit yourself :-) */
  32. #endif /* DRAND48 */
  33. #endif /* RANDOM */
  34. }
  35.  
  36. /*
  37.  * The function time() can't really be trusted to return an integer.
  38.  * But this game uses the 'current_time', which is an integer number
  39.  * of seconds. To make this more portable, the following functions
  40.  * should be defined in such a way as to retrun the number of seconds since
  41.  * some chosen year. The old behaviour of time(), is to return the number
  42.  * of seconds since 1970.
  43.  */
  44.  
  45. int get_current_time() {
  46.     return (int)time(0l);    /* Just use the old time() for now */
  47. }
  48.  
  49. char *time_string(t)
  50.     int t;
  51. {
  52.     return ctime((time_t *)&t);
  53. }
  54.