137c3bdbeSkamil /* Header: util.h,v 7.0 86/10/08 15:14:37 lwall Exp */ 2c503d12fSkamil 337c3bdbeSkamil /* Log: util.h,v 4c503d12fSkamil * Revision 7.0 86/10/08 15:14:37 lwall 5c503d12fSkamil * Split into separate files. Added amoebas and pirates. 6c503d12fSkamil * 7c503d12fSkamil */ 8c503d12fSkamil 9c503d12fSkamil #define RANDRAND 1152921504606846976.0 /* that's 2**60 */ 10c503d12fSkamil #define HALFRAND 0x40000000 /* that's 2**30 */ 117839ca65Schristos #define myrand() (int)random() 12c503d12fSkamil #define rand_mod(m) ((myrand() / 37) % (m)) /* pick number in 0..m-1 */ 13c503d12fSkamil /* 14c503d12fSkamil * The reason for the /37 above is that our random number generator yields 15c503d12fSkamil * successive evens and odds, for some reason. This makes strange star maps. 16c503d12fSkamil */ 17c503d12fSkamil 18c503d12fSkamil /* we get fractions of seconds from calling ftime on timebuf */ 19c503d12fSkamil 20*968a1034Sjoerg extern struct timespec timebuf; 217839ca65Schristos #define roundsleep(x) (clock_gettime(CLOCK_REALTIME, &timebuf),sleep(timebuf.tv_nsec > 5000000000 ?x+1:x)) 22c503d12fSkamil 238a5cd4c8Skamil #define waiting 0 24c503d12fSkamil 25c503d12fSkamil #ifdef NOTDEF 26c503d12fSkamil EXT int len_last_line_got INIT(0); 27c503d12fSkamil /* strlen of some_buf after */ 28c503d12fSkamil /* some_buf = get_a_line(bufptr,buffersize,fp) */ 29c503d12fSkamil #endif 30c503d12fSkamil 31c503d12fSkamil #ifdef NOTDEF 32c503d12fSkamil /* is the string for makedir a directory name or a filename? */ 33c503d12fSkamil 34c503d12fSkamil #define MD_DIR 0 35c503d12fSkamil #define MD_FILE 1 36c503d12fSkamil #endif 37c503d12fSkamil 38c8c17207Schristos void util_init(void); 39c8c17207Schristos void movc3(int, char *, char *); 40*968a1034Sjoerg __dead void no_can_do(const char *); 41c8c17207Schristos int exdis(int); 42c8c17207Schristos void *safemalloc(size_t size); 43c8c17207Schristos char *safecpy(char *, const char *, size_t); 44c8c17207Schristos char *cpytill(char *, const char *, int); 45c8c17207Schristos char *instr(const char *, const char *); 46c503d12fSkamil #ifdef SETUIDGID 47c8c17207Schristos int eaccess(const char *, mode_t); 48c503d12fSkamil #endif 49*968a1034Sjoerg __dead void prexit(const char *); 50c8c17207Schristos char *savestr(const char *); 51c8c17207Schristos char *getval(const char *, const char *); 52