Home | History | Annotate | Line # | Download | only in warp
util.h revision 1.4
      1 /* Header: util.h,v 7.0 86/10/08 15:14:37 lwall Exp */
      2 
      3 /* Log:	util.h,v
      4  * Revision 7.0  86/10/08  15:14:37  lwall
      5  * Split into separate files.  Added amoebas and pirates.
      6  *
      7  */
      8 
      9 #if RANDBITS < 15 || defined(lint)
     10 #define rand_mod(m) getpid()
     11 #define RANDRAND 0.0
     12 #define HALFRAND 0
     13 #define myrand() getpid()
     14 #else
     15 #if RANDBITS == 15	/* 15 bits of rand()? */
     16 #define RANDRAND 268435456.0 /* that's 2**28 */
     17 #define HALFRAND 0x4000 /* that's 2**14 */
     18 int rand(void);
     19 #define myrand() (rand()&32767)
     20 #define rand_mod(m) ((int)((double)myrand() / 32768.0 * ((double)(m))))
     21 /* pick number in 0..m-1 */
     22 
     23 #else
     24 
     25 #if RANDBITS < 31	/* 16 bits of rand()? */
     26 #define RANDRAND 1073741824.0 /* that's 2**30 */
     27 #define HALFRAND 0x8000 /* that's 2**15 */
     28 unsigned rand();
     29 #define myrand() (rand()&65535)
     30 #define rand_mod(m) ((int)((double)myrand() / 65536.0 * ((double)(m))))
     31 /* pick number in 0..m-1 */
     32 
     33 #else		/* assume 31 bits */
     34 #define RANDRAND 1152921504606846976.0 /* that's 2**60 */
     35 #define HALFRAND 0x40000000 /* that's 2**30 */
     36 long rand();
     37 #define myrand() rand()
     38 #define rand_mod(m) ((myrand() / 37) % (m)) /* pick number in 0..m-1 */
     39 /*
     40  * The reason for the /37 above is that our random number generator yields
     41  * successive evens and odds, for some reason.  This makes strange star maps.
     42  */
     43 #endif
     44 #endif
     45 #endif
     46 
     47 
     48     /* we get fractions of seconds from calling ftime on timebuf */
     49 
     50 EXT struct timeb timebuf;
     51 #define roundsleep(x) (ftime(&timebuf),sleep(timebuf.millitm > 500?x+1:x))
     52 
     53 #define waiting 0
     54 
     55 #ifdef NOTDEF
     56 EXT int len_last_line_got INIT(0);
     57 			/* strlen of some_buf after */
     58 			/*  some_buf = get_a_line(bufptr,buffersize,fp) */
     59 #endif
     60 
     61 #ifdef NOTDEF
     62 /* is the string for makedir a directory name or a filename? */
     63 
     64 #define MD_DIR 0
     65 #define MD_FILE 1
     66 #endif
     67 
     68 void util_init(void);
     69 void movc3(int, char *, char *);
     70 void no_can_do(const char *);
     71 int exdis(int);
     72 void *safemalloc(size_t size);
     73 char *safecpy(char *, const char *, size_t);
     74 char *cpytill(char *, const char *, int);
     75 char *instr(const char *, const char *);
     76 #ifdef SETUIDGID
     77 int eaccess(const char *, mode_t);
     78 #endif
     79 void prexit(const char *);
     80 char *savestr(const char *);
     81 char *getval(const char *, const char *);
     82