Use more portable random seed generation.
The new function md_random_seed() has replaced time() + getpid() and similar methods. Putting everything in mdport.c slightly reduces the warnings and workarounds.
This commit is contained in:
parent
c194ec3dc9
commit
62047972cc
29 changed files with 123 additions and 81 deletions
|
|
@ -31,8 +31,6 @@ main(int argc, char *argv[], char *envp[])
|
|||
char *env;
|
||||
struct linked_list *item;
|
||||
struct object *obj;
|
||||
int lowtime;
|
||||
time_t now;
|
||||
|
||||
md_init(MD_STRIP_CTRL_KEYPAD);
|
||||
|
||||
|
|
@ -130,9 +128,6 @@ main(int argc, char *argv[], char *envp[])
|
|||
if (!use_savedir)
|
||||
md_normaluser();
|
||||
|
||||
time(&now);
|
||||
lowtime = (int) now;
|
||||
|
||||
env = getenv("SEED");
|
||||
|
||||
if (env)
|
||||
|
|
@ -146,7 +141,7 @@ main(int argc, char *argv[], char *envp[])
|
|||
dnum = seed;
|
||||
}
|
||||
else
|
||||
dnum = lowtime + md_getpid();
|
||||
dnum = md_random_seed();
|
||||
|
||||
if (wizard || env)
|
||||
printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@
|
|||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#define NOOP(x) (x += 0)
|
||||
|
||||
|
|
@ -415,16 +416,6 @@ md_getuid(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
pid_t
|
||||
md_getpid(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return( _getpid() );
|
||||
#else
|
||||
return( getpid() );
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
md_getusername(void)
|
||||
{
|
||||
|
|
@ -1612,3 +1603,16 @@ md_unlockfile(FILE *fp)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
md_random_seed(void)
|
||||
{
|
||||
unsigned int seed;
|
||||
seed = (unsigned int) time((time_t *) NULL);
|
||||
#ifdef _WIN32
|
||||
seed += _getpid();
|
||||
#else
|
||||
seed += getpid();
|
||||
#endif
|
||||
return seed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,9 +65,6 @@
|
|||
#ifndef uid_t
|
||||
typedef unsigned int uid_t;
|
||||
#endif
|
||||
#ifndef pid_t
|
||||
typedef unsigned int pid_t;
|
||||
#endif
|
||||
|
||||
#elif defined(__CYGWIN__)
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
|
@ -163,7 +160,6 @@ char * md_gethomedir(void);
|
|||
char * md_getusername(void);
|
||||
uid_t md_getuid(void);
|
||||
char * md_getpass(char *prompt);
|
||||
pid_t md_getpid(void);
|
||||
char * md_getrealname(uid_t uid);
|
||||
void md_init(int options);
|
||||
int md_killchar(void);
|
||||
|
|
@ -190,6 +186,7 @@ int md_loadav(double *avg);
|
|||
void md_start_checkout_timer(int time);
|
||||
void md_stop_checkout_timer(void);
|
||||
long md_memused(void);
|
||||
int md_ucount(void);
|
||||
int md_unlockfile(FILE *fp);
|
||||
int md_lockfile(FILE *fp);
|
||||
int md_ucount(void);
|
||||
int md_unlockfile(FILE *fp);
|
||||
int md_lockfile(FILE *fp);
|
||||
unsigned int md_random_seed(void);
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ restore(char *file, char **envp)
|
|||
setup();
|
||||
clearok(curscr, TRUE);
|
||||
touchwin(cw);
|
||||
srand(md_getpid());
|
||||
srand(md_random_seed());
|
||||
status();
|
||||
playit();
|
||||
/*NOTREACHED*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue