Mercurial > hg > early-roguelike
comparison arogue5/mdport.c @ 72:46f39359c4a7
arogue5: avoid segfaulting if getpwuid() fails.
author | elwin |
---|---|
date | Sat, 11 Aug 2012 23:45:34 +0000 |
parents | c49f7927b0fa |
children | 3192c1e03970 |
comparison
equal
deleted
inserted
replaced
71:d8e5c5dd9b55 | 72:46f39359c4a7 |
---|---|
232 #if !defined(_WIN32) && !defined(DJGPP) | 232 #if !defined(_WIN32) && !defined(DJGPP) |
233 struct passwd *pw; | 233 struct passwd *pw; |
234 | 234 |
235 pw = getpwuid(getuid()); | 235 pw = getpwuid(getuid()); |
236 | 236 |
237 l = pw->pw_name; | 237 if (pw != NULL) |
238 l = pw->pw_name; | |
239 else | |
240 l = ""; | |
238 #endif | 241 #endif |
239 | 242 |
240 if ((l == NULL) || (*l == '\0')) | 243 if ((l == NULL) || (*l == '\0')) |
241 if ( (l = getenv("USERNAME")) == NULL ) | 244 if ( (l = getenv("USERNAME")) == NULL ) |
242 if ( (l = getenv("LOGNAME")) == NULL ) | 245 if ( (l = getenv("LOGNAME")) == NULL ) |
263 #else | 266 #else |
264 char slash = '/'; | 267 char slash = '/'; |
265 struct passwd *pw; | 268 struct passwd *pw; |
266 pw = getpwuid(getuid()); | 269 pw = getpwuid(getuid()); |
267 | 270 |
268 h = pw->pw_dir; | 271 if (pw != NULL) |
272 h = pw->pw_dir; | |
273 else | |
274 h = ""; | |
269 | 275 |
270 if (strcmp(h,"/") == 0) | 276 if (strcmp(h,"/") == 0) |
271 h = NULL; | 277 h = NULL; |
272 #endif | 278 #endif |
273 homedir[0] = 0; | 279 homedir[0] = 0; |
323 char *def = "C:\\COMMAND.COM"; | 329 char *def = "C:\\COMMAND.COM"; |
324 #else | 330 #else |
325 char *def = "/bin/sh"; | 331 char *def = "/bin/sh"; |
326 struct passwd *pw; | 332 struct passwd *pw; |
327 pw = getpwuid(getuid()); | 333 pw = getpwuid(getuid()); |
328 s = pw->pw_shell; | 334 if (pw != NULL) |
335 s = pw->pw_shell; | |
336 else | |
337 s = ""; | |
329 #endif | 338 #endif |
330 if ((s == NULL) || (*s == '\0')) | 339 if ((s == NULL) || (*s == '\0')) |
331 if ( (s = getenv("COMSPEC")) == NULL) | 340 if ( (s = getenv("COMSPEC")) == NULL) |
332 if ( (s = getenv("SHELL")) == NULL) | 341 if ( (s = getenv("SHELL")) == NULL) |
333 if ( (s = getenv("SystemRoot")) == NULL) | 342 if ( (s = getenv("SystemRoot")) == NULL) |