srogue: add and use more md_* portable functions.
Privileges and memory usage checks are now more portable.
This commit is contained in:
parent
791df4324f
commit
b9cc9cf3a7
6 changed files with 74 additions and 22 deletions
|
|
@ -29,8 +29,6 @@
|
|||
#endif
|
||||
|
||||
#ifdef BSD
|
||||
#define srand48(seed) srandom(seed)
|
||||
#define lrand48() random()
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -57,13 +55,8 @@ char **envp;
|
|||
if (homedir == NULL)
|
||||
homedir = "";
|
||||
|
||||
playuid = getuid();
|
||||
|
||||
if (setuid(playuid) < 0) {
|
||||
printf("Cannot change to effective uid: %d\n", playuid);
|
||||
exit(1);
|
||||
}
|
||||
playgid = getgid();
|
||||
playuid = md_getuid();
|
||||
playgid = md_getgid();
|
||||
|
||||
/* check for print-score option */
|
||||
#ifdef SCOREFILE
|
||||
|
|
@ -121,6 +114,9 @@ char **envp;
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!use_savedir)
|
||||
md_droppriv();
|
||||
|
||||
/* get home and options from environment */
|
||||
|
||||
if ((env = getenv("HOME")) != NULL)
|
||||
|
|
@ -177,7 +173,7 @@ char **envp;
|
|||
|
||||
fflush(stdout);
|
||||
seed = dnum;
|
||||
srand48(seed); /* init rnd number gen */
|
||||
srandom(seed); /* init rnd number gen */
|
||||
|
||||
md_onsignal_exit(); /* just in case */
|
||||
|
||||
|
|
@ -358,7 +354,7 @@ int range;
|
|||
if (range == 0)
|
||||
wh = 0;
|
||||
else {
|
||||
wh = lrand48() % range;
|
||||
wh = random() % range;
|
||||
wh &= 0x7FFFFFFF;
|
||||
}
|
||||
return wh;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue