Mercurial > hg > early-roguelike
comparison srogue/main.c @ 120:d6b7c3fb37ea
srogue: add and use more md_* portable functions.
Privileges and memory usage checks are now more portable.
author | John "Elwin" Edwards |
---|---|
date | Fri, 02 May 2014 15:06:23 -0700 |
parents | 458df24e973d |
children | e6c8652473fe |
comparison
equal
deleted
inserted
replaced
119:458df24e973d | 120:d6b7c3fb37ea |
---|---|
27 #ifdef ATT | 27 #ifdef ATT |
28 #include <time.h> | 28 #include <time.h> |
29 #endif | 29 #endif |
30 | 30 |
31 #ifdef BSD | 31 #ifdef BSD |
32 #define srand48(seed) srandom(seed) | |
33 #define lrand48() random() | |
34 #include <sys/time.h> | 32 #include <sys/time.h> |
35 #endif | 33 #endif |
36 | 34 |
37 #include "rogue.ext" | 35 #include "rogue.ext" |
38 | 36 |
55 #endif | 53 #endif |
56 | 54 |
57 if (homedir == NULL) | 55 if (homedir == NULL) |
58 homedir = ""; | 56 homedir = ""; |
59 | 57 |
60 playuid = getuid(); | 58 playuid = md_getuid(); |
61 | 59 playgid = md_getgid(); |
62 if (setuid(playuid) < 0) { | |
63 printf("Cannot change to effective uid: %d\n", playuid); | |
64 exit(1); | |
65 } | |
66 playgid = getgid(); | |
67 | 60 |
68 /* check for print-score option */ | 61 /* check for print-score option */ |
69 #ifdef SCOREFILE | 62 #ifdef SCOREFILE |
70 strncpy(scorefile, SCOREFILE, LINLEN); | 63 strncpy(scorefile, SCOREFILE, LINLEN); |
71 scorefile[LINLEN - 1] = '\0'; | 64 scorefile[LINLEN - 1] = '\0'; |
119 use_savedir = FALSE; | 112 use_savedir = FALSE; |
120 } | 113 } |
121 } | 114 } |
122 #endif | 115 #endif |
123 | 116 |
117 if (!use_savedir) | |
118 md_droppriv(); | |
119 | |
124 /* get home and options from environment */ | 120 /* get home and options from environment */ |
125 | 121 |
126 if ((env = getenv("HOME")) != NULL) | 122 if ((env = getenv("HOME")) != NULL) |
127 strcpy(home, env); | 123 strcpy(home, env); |
128 else { | 124 else { |
175 else | 171 else |
176 printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami); | 172 printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami); |
177 | 173 |
178 fflush(stdout); | 174 fflush(stdout); |
179 seed = dnum; | 175 seed = dnum; |
180 srand48(seed); /* init rnd number gen */ | 176 srandom(seed); /* init rnd number gen */ |
181 | 177 |
182 md_onsignal_exit(); /* just in case */ | 178 md_onsignal_exit(); /* just in case */ |
183 | 179 |
184 init_everything(); | 180 init_everything(); |
185 | 181 |
356 reg int wh; | 352 reg int wh; |
357 | 353 |
358 if (range == 0) | 354 if (range == 0) |
359 wh = 0; | 355 wh = 0; |
360 else { | 356 else { |
361 wh = lrand48() % range; | 357 wh = random() % range; |
362 wh &= 0x7FFFFFFF; | 358 wh &= 0x7FFFFFFF; |
363 } | 359 } |
364 return wh; | 360 return wh; |
365 } | 361 } |
366 | 362 |