From: Holger Schemel Date: Mon, 23 Nov 1998 21:52:54 +0000 (+0100) Subject: rnd-19981123-6 X-Git-Tag: 1.2.0^2~10 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=e6fa0d1ce485a8a23d282fa9fbbd61474044af2b;p=rocksndiamonds.git rnd-19981123-6 --- diff --git a/src/files.c b/src/files.c index d28c1f48..dfd9c85f 100644 --- a/src/files.c +++ b/src/files.c @@ -89,8 +89,7 @@ static char *getUserDataDir() char *home_dir = getHomeDir(); char *data_dir = USERDATA_DIRECTORY; - userdata_dir = checked_malloc(strlen(home_dir) + strlen(data_dir) + 2); - sprintf(userdata_dir, "%s/%s", home_dir, data_dir); + userdata_dir = getPath2(home_dir, data_dir); } return userdata_dir; @@ -110,10 +109,10 @@ static char *getUserLevelDir(char *level_subdir) if (userlevel_dir) free(userlevel_dir); - userlevel_dir = checked_malloc(strlen(data_dir) + strlen(userlevel_subdir) + - strlen(level_subdir) + 3); - sprintf(userlevel_dir, "%s/%s%s%s", data_dir, userlevel_subdir, - (strlen(level_subdir) > 0 ? "/" : ""), level_subdir); + if (strlen(level_subdir) > 0) + userlevel_dir = getPath3(data_dir, userlevel_subdir, level_subdir); + else + userlevel_dir = getPath2(data_dir, userlevel_subdir); return userlevel_dir; } @@ -127,10 +126,10 @@ static char *getTapeDir(char *level_subdir) if (tape_dir) free(tape_dir); - tape_dir = checked_malloc(strlen(data_dir) + strlen(tape_subdir) + - strlen(level_subdir) + 3); - sprintf(tape_dir, "%s/%s%s%s", data_dir, tape_subdir, - (strlen(level_subdir) > 0 ? "/" : ""), level_subdir); + if (strlen(level_subdir) > 0) + tape_dir = getPath3(data_dir, tape_subdir, level_subdir); + else + tape_dir = getPath2(data_dir, tape_subdir); return tape_dir; } @@ -144,10 +143,10 @@ static char *getScoreDir(char *level_subdir) if (score_dir) free(score_dir); - score_dir = checked_malloc(strlen(data_dir) + strlen(score_subdir) + - strlen(level_subdir) + 3); - sprintf(score_dir, "%s/%s%s%s", data_dir, score_subdir, - (strlen(level_subdir) > 0 ? "/" : ""), level_subdir); + if (strlen(level_subdir) > 0) + score_dir = getPath3(data_dir, score_subdir, level_subdir); + else + score_dir = getPath2(data_dir, score_subdir); return score_dir; } @@ -1403,16 +1402,16 @@ void LoadLevelInfo() static void SaveUserLevelInfo() { - char filename[MAX_FILENAME_LEN]; + char *filename; FILE *file; int i; - sprintf(filename, "%s/%s", - getUserLevelDir(getLoginName()), LEVELINFO_FILENAME); + filename = getPath2(getUserLevelDir(getLoginName()), LEVELINFO_FILENAME); if (!(file = fopen(filename, "w"))) { Error(ERR_WARN, "cannot write level info file '%s'", filename); + free(filename); return; } @@ -1428,19 +1427,20 @@ static void SaveUserLevelInfo() fprintf(file, "%s\n", getSetupLine("", i)); fclose(file); + free(filename); chmod(filename, SETUP_PERMS); } void LoadSetup() { - char filename[MAX_FILENAME_LEN]; + char *filename; struct SetupFileList *setup_file_list = NULL; /* always start with reliable default values */ setSetupInfoToDefaults(&setup); - sprintf(filename, "%s/%s", getSetupDir(), SETUP_FILENAME); + filename = getPath2(getSetupDir(), SETUP_FILENAME); setup_file_list = loadSetupFileList(filename); @@ -1467,6 +1467,8 @@ void LoadSetup() } else Error(ERR_WARN, "using default setup values"); + + free(filename); } static char *getSetupLine(char *prefix, int token_nr) @@ -1535,16 +1537,17 @@ static char *getSetupLine(char *prefix, int token_nr) void SaveSetup() { int i, pnr; - char filename[MAX_FILENAME_LEN]; + char *filename; FILE *file; InitUserDataDirectory(); - sprintf(filename, "%s/%s", getSetupDir(), SETUP_FILENAME); + filename = getPath2(getSetupDir(), SETUP_FILENAME); if (!(file = fopen(filename, "w"))) { Error(ERR_WARN, "cannot write setup file '%s'", filename); + free(filename); return; } @@ -1577,19 +1580,20 @@ void SaveSetup() } fclose(file); + free(filename); chmod(filename, SETUP_PERMS); } void LoadLevelSetup() { - char filename[MAX_FILENAME_LEN]; + char *filename; /* always start with reliable default values */ leveldir_nr = 0; level_nr = 0; - sprintf(filename, "%s/%s", getSetupDir(), LEVELSETUP_FILENAME); + filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); if (level_setup_list) freeSetupFileList(level_setup_list); @@ -1612,11 +1616,13 @@ void LoadLevelSetup() LEVELSETUP_COOKIE); Error(ERR_WARN, "using default setup values"); } + + free(filename); } void SaveLevelSetup() { - char filename[MAX_FILENAME_LEN]; + char *filename; struct SetupFileList *list_entry = level_setup_list; FILE *file; @@ -1628,11 +1634,12 @@ void SaveLevelSetup() setTokenValue(level_setup_list, leveldir[leveldir_nr].filename, int2str(level_nr, 0)); - sprintf(filename, "%s/%s", getSetupDir(), LEVELSETUP_FILENAME); + filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME); if (!(file = fopen(filename, "w"))) { Error(ERR_WARN, "cannot write setup file '%s'", filename); + free(filename); return; } @@ -1652,6 +1659,7 @@ void SaveLevelSetup() } fclose(file); + free(filename); chmod(filename, SETUP_PERMS); } diff --git a/src/misc.c b/src/misc.c index c2c85e40..f17c52d3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -361,10 +361,8 @@ void GetOptions(char *argv[]) printf("--basepath == '%s'\n", options.base_directory); /* adjust path for level directory accordingly */ - options.level_directory = checked_malloc(strlen(options.base_directory) + - strlen(LEVELS_DIRECTORY) + 2); - sprintf(options.level_directory, "%s/%s", - options.base_directory, LEVELS_DIRECTORY); + options.level_directory = + getPath2(options.base_directory, LEVELS_DIRECTORY); } else if (strncmp(option, "-levels", option_len) == 0) { diff --git a/src/netserv.c b/src/netserv.c index f29a19c8..49bc51e7 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -46,7 +46,6 @@ struct user unsigned char writbuf[MAX_BUFFER_SIZE]; int nwrite; char playing; - int lines; unsigned int games; unsigned char action; int action_received; @@ -359,7 +358,6 @@ static void Handle_OP_START_PLAYING(struct user *u) { w->active = 1; w->playing = 1; - w->lines = 0; w->nextvictim = NULL; for (v=NEXT(w); v!=w; v=NEXT(v)) {