Mercurial > hg > early-roguelike
diff srogue/main.c @ 184:7c059ec2a2c7
Merge Super-Rogue fixes into the MSVC testing branch.
author | John "Elwin" Edwards |
---|---|
date | Sun, 02 Aug 2015 12:25:44 -0400 |
parents | db1c9a21a7c3 |
children | 7c552cbc6ad9 |
line wrap: on
line diff
--- a/srogue/main.c Sat Aug 01 21:23:55 2015 -0400 +++ b/srogue/main.c Sun Aug 02 12:25:44 2015 -0400 @@ -34,6 +34,11 @@ #include "rogue.ext" +void open_records(void); + +extern int scorefd; +extern FILE *logfile; + main(argc, argv, envp) char **argv; char **envp; @@ -64,12 +69,15 @@ scorefile[LINLEN - 1] = '\0'; #else - strcpy(scorefile, homedir); + strncpy(scorefile, homedir, LINLEN-11); + if (scorefile[LINLEN-12] != '\0') + scorefile[0] = '\0'; if (*scorefile) strcat(scorefile,"/"); strcat(scorefile, "srogue.scr"); #endif + open_records(); if(argc >= 2 && strcmp(argv[1], "-s") == 0) { @@ -115,7 +123,7 @@ #endif if (!use_savedir) - md_droppriv(); + md_normaluser(); /* get home and options from environment */ @@ -438,23 +446,25 @@ char * roguehome() { - static char path[1024]; + static char path[LINLEN+16]; char *end,*home; if ( (home = getenv("ROGUEHOME")) != NULL) { if (*home) { - strncpy(path, home, PATH_MAX - 20); - - end = &path[strlen(path)-1]; - + /* LINLEN - 11 is all that will fit into scorefile */ + strncpy(path, home, LINLEN - 11); + if (path[LINLEN - 12] == '\0') + { + end = &path[strlen(path)-1]; + while( (end >= path) && ((*end == '/') || (*end == '\\'))) + *end-- = '\0'; - while( (end >= path) && ((*end == '/') || (*end == '\\'))) - *end-- = '\0'; - - if (directory_exists(path)) - return(path); + if (directory_exists(path)) + return(path); + } + /* Otherwise home was truncated and should be ignored */ } } @@ -472,3 +482,14 @@ return(NULL); } +void +open_records(void) +{ + if (scorefd < 0) + scorefd = open(scorefile, O_RDWR | O_CREAT, 0666); +#ifdef LOGFILE + if (logfile == NULL) + logfile = fopen(LOGFILE, "a"); +#endif +} +