comparison 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
comparison
equal deleted inserted replaced
183:7f5f5f1ba09c 184:7c059ec2a2c7
32 #include <sys/time.h> 32 #include <sys/time.h>
33 #endif 33 #endif
34 34
35 #include "rogue.ext" 35 #include "rogue.ext"
36 36
37 void open_records(void);
38
39 extern int scorefd;
40 extern FILE *logfile;
41
37 main(argc, argv, envp) 42 main(argc, argv, envp)
38 char **argv; 43 char **argv;
39 char **envp; 44 char **envp;
40 { 45 {
41 register char *env; 46 register char *env;
62 #ifdef SCOREFILE 67 #ifdef SCOREFILE
63 strncpy(scorefile, SCOREFILE, LINLEN); 68 strncpy(scorefile, SCOREFILE, LINLEN);
64 scorefile[LINLEN - 1] = '\0'; 69 scorefile[LINLEN - 1] = '\0';
65 #else 70 #else
66 71
67 strcpy(scorefile, homedir); 72 strncpy(scorefile, homedir, LINLEN-11);
73 if (scorefile[LINLEN-12] != '\0')
74 scorefile[0] = '\0';
68 75
69 if (*scorefile) 76 if (*scorefile)
70 strcat(scorefile,"/"); 77 strcat(scorefile,"/");
71 strcat(scorefile, "srogue.scr"); 78 strcat(scorefile, "srogue.scr");
72 #endif 79 #endif
80 open_records();
73 81
74 if(argc >= 2 && strcmp(argv[1], "-s") == 0) 82 if(argc >= 2 && strcmp(argv[1], "-s") == 0)
75 { 83 {
76 showtop(0); 84 showtop(0);
77 exit(0); 85 exit(0);
113 } 121 }
114 } 122 }
115 #endif 123 #endif
116 124
117 if (!use_savedir) 125 if (!use_savedir)
118 md_droppriv(); 126 md_normaluser();
119 127
120 /* get home and options from environment */ 128 /* get home and options from environment */
121 129
122 if ((env = getenv("HOME")) != NULL) 130 if ((env = getenv("HOME")) != NULL)
123 strcpy(home, env); 131 strcpy(home, env);
436 } 444 }
437 445
438 char * 446 char *
439 roguehome() 447 roguehome()
440 { 448 {
441 static char path[1024]; 449 static char path[LINLEN+16];
442 char *end,*home; 450 char *end,*home;
443 451
444 if ( (home = getenv("ROGUEHOME")) != NULL) 452 if ( (home = getenv("ROGUEHOME")) != NULL)
445 { 453 {
446 if (*home) 454 if (*home)
447 { 455 {
448 strncpy(path, home, PATH_MAX - 20); 456 /* LINLEN - 11 is all that will fit into scorefile */
449 457 strncpy(path, home, LINLEN - 11);
450 end = &path[strlen(path)-1]; 458 if (path[LINLEN - 12] == '\0')
451 459 {
452 460 end = &path[strlen(path)-1];
453 while( (end >= path) && ((*end == '/') || (*end == '\\'))) 461 while( (end >= path) && ((*end == '/') || (*end == '\\')))
454 *end-- = '\0'; 462 *end-- = '\0';
455 463
456 if (directory_exists(path)) 464 if (directory_exists(path))
457 return(path); 465 return(path);
466 }
467 /* Otherwise home was truncated and should be ignored */
458 } 468 }
459 } 469 }
460 470
461 if (directory_exists("/var/games/roguelike")) 471 if (directory_exists("/var/games/roguelike"))
462 return("/var/games/roguelike"); 472 return("/var/games/roguelike");
470 return("/games/roguelik"); 480 return("/games/roguelik");
471 481
472 return(NULL); 482 return(NULL);
473 } 483 }
474 484
485 void
486 open_records(void)
487 {
488 if (scorefd < 0)
489 scorefd = open(scorefile, O_RDWR | O_CREAT, 0666);
490 #ifdef LOGFILE
491 if (logfile == NULL)
492 logfile = fopen(LOGFILE, "a");
493 #endif
494 }
495