void kinsol_errorHandler(int error_code, const char* module, const char* function, char* msg, void* user_data) { if(DEBUG_FLAG(LOG_INIT)) { WARNING3("[module] %s | [function] %s | [error_code] %d", module, function, error_code); WARNING_AL1("%s", msg); } }
/** Create the savegame directory * * The directory will be created as defined in options.dir_savegame. * * \note The access will be set to 0777 (worldwritable) * * \return -1 on error * \return 0 on success */ int create_save_dir(void) { if (mkdir(options.dir_savegame, 0777) < 0 && errno != EEXIST) { WARNING3("can't create savegame directory `%s': %s", options.dir_savegame, strerror(errno)); return -1; } return 0; }
int remove_savedat(const char *name) { size_t len_base = strlen(options.dir_savegame) + 1; size_t len_name = strlen(name) + 1; char *cooked = xmalloc(len_base + len_name); int rv = 0; sprintf(cooked, "%s/%s", options.dir_savegame, name); INFO2("removing save game file `%s'", cooked); fix_pathsep(cooked); rv = remove(cooked); if (rv < 0 && errno != ENOENT) WARNING3("failed to remove save game file `%s': %s", cooked, strerror(errno)); free(cooked); return rv; }
static FILE* try_fopen(const char *fname, const char *mode) { FILE* fp = NULL; assert(fname); assert(mode); TRACE3("trying to open `%s' (mode %s)", fname, mode); fp = fopen(fname, mode); /** \todo ENOENT is POSIX, ANSI equivalent for file does not exist??? */ if (!fp && errno != ENOENT) { int esave = errno; WARNING3("can't access file `%s': %s", fname, strerror(errno)); errno = esave; } return fp; }
/** tries to find a file and open it * * The function knows about the relative * position of certain filetypes. It retrieves * the position savegamedir and gamedatadir from * options. * * \param name Name of the file to open * \param mode mode to file should be opened in * \param type Type of the file eg. FT_SAVE, FT_DATA, ... * * \return fileinformation including opened filehandle */ static file try_find_file(const char *name, const char *mode, int type) { file f = {NULL, NULL}; char *gd = options.dir_gamedata; char *sd = options.dir_savegame; char *where = ""; const char *newmode = mode; DEBUG2("looking for file `%s'", name); /** \note allows write access only to savegame files */ if (type != FT_SAVE) { if (strchr(mode, 'w') || strchr(mode, 'a') || strncmp(mode, "r+", 2) == 0) { char *newmode; if (strchr(mode, 'b')) newmode = "rb"; else newmode = "r"; DEBUG3("access mode changed from `%s' to `%s'", mode, newmode); } } switch (type) { case FT_DATA: f = s_open_helper(gd, name, newmode, "gamedata", NULL); where = "game data"; break; case FT_SAVE: case FT_SAVE_CHECK: f = s_open_helper(sd, name, newmode, "", NULL); where = "savegame"; break; case FT_AUDIO: f = s_open_helper(gd, name, newmode, "audio/mission", "audio/music", "audio/news", "audio/sounds", NULL); where = "audio"; break; case FT_VIDEO: f = s_open_helper(gd, name, newmode, "video/mission", "video/news", "video/training", NULL); where = "video"; break; case FT_IMAGE: f = s_open_helper(gd, name, newmode, "images", NULL); where = "image"; break; case FT_MIDI: f = s_open_helper(gd, name, newmode, "audio/midi", "midi", "audio/music", NULL); where = "midi"; break; default: assert("Unknown FT_* specified"); } if (f.handle == NULL && type != FT_SAVE_CHECK) { int serrno = errno; WARNING3("can't find file `%s' in %s dir(s)", name, where); errno = serrno; } return f; }
static void map_file_parse (kpathsea kpse, const_string map_filename) { char *orig_l; unsigned map_lineno = 0; FILE *f = xfopen (map_filename, FOPEN_R_MODE); if (kpse->record_input) kpse->record_input (map_filename); while ((orig_l = read_line (f)) != NULL) { string filename; string l = orig_l; /* save for free() */ string comment_loc = strrchr (l, '%'); if (!comment_loc) { comment_loc = strstr (l, "@c"); } /* Ignore anything after a % or @c. */ if (comment_loc) *comment_loc = 0; map_lineno++; /* Skip leading whitespace so we can use strlen below. Can't use strtok since this routine is recursive. */ while (*l && ISSPACE (*l)) l++; /* If we don't have any filename, that's ok, the line is blank. */ filename = token (l); if (filename) { string alias = token (l + strlen (filename)); if (STREQ (filename, "include")) { if (alias == NULL) { WARNING2 ("%s:%u: Filename argument for include directive missing", map_filename, map_lineno); } else { string include_fname = kpathsea_path_search (kpse, kpse->map_path, alias, false); if (include_fname) { map_file_parse (kpse, include_fname); if (include_fname != alias) free (include_fname); } else { WARNING3 ("%s:%u: Can't find fontname include file `%s'", map_filename, map_lineno, alias); } free (alias); free (filename); } /* But if we have a filename and no alias, something's wrong. */ } else if (alias == NULL) { WARNING3 ("%s:%u: Fontname alias missing for filename `%s'", map_filename, map_lineno, filename); free (filename); } else { /* We've got everything. Insert the new entry. They were already dynamically allocated by token(), so don't bother with xstrdup. */ hash_insert_normalized (&(kpse->map), alias, filename); } } free (orig_l); } xfclose (f, map_filename); }