X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flibgame%2Fmisc.c;h=e144979a7bb40ed1c2a38132e7860629477041ff;hb=681721dddc91bcdaef50002d1e861cc8d484e938;hp=5814e8d17f9e42464e69c39f77fe6b67c58cb5f5;hpb=ff56a43aa3799aa3357f4deca4d6482fc25a6a41;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 5814e8d1..e144979a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1,7 +1,7 @@ /*********************************************************** * Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1994-2000 Artsoft Entertainment * +* (c) 1994-2001 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -551,15 +551,18 @@ void Error(int mode, char *format, ...) { char *process_name = ""; FILE *error = stderr; + char *newline = "\n"; /* display warnings only when running in verbose mode */ if (mode & ERR_WARN && !options.verbose) return; #if !defined(PLATFORM_UNIX) + newline = "\r\n"; + if ((error = openErrorFile()) == NULL) { - printf("Cannot write to error output file!\n"); + printf("Cannot write to error output file!%s", newline); program.exit_function(1); } #endif @@ -584,15 +587,16 @@ void Error(int mode, char *format, ...) vfprintf(error, format, ap); va_end(ap); - fprintf(error, "\n"); + fprintf(error, "%s", newline); } if (mode & ERR_HELP) - fprintf(error, "%s: Try option '--help' for more information.\n", - program.command_basename); + fprintf(error, "%s: Try option '--help' for more information.%s", + program.command_basename, newline); if (mode & ERR_EXIT) - fprintf(error, "%s%s: aborting\n", program.command_basename, process_name); + fprintf(error, "%s%s: aborting%s", + program.command_basename, process_name, newline); if (error != stderr) fclose(error); @@ -630,6 +634,16 @@ void *checked_calloc(unsigned long size) return ptr; } +void *checked_realloc(void *ptr, unsigned long size) +{ + ptr = realloc(ptr, size); + + if (ptr == NULL) + Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size); + + return ptr; +} + short getFile16BitInteger(FILE *file, int byte_order) { if (byte_order == BYTE_ORDER_BIG_ENDIAN) @@ -1314,7 +1328,7 @@ FILE *openErrorFile() FILE *error_file; filename = getPath2(getUserDataDir(), ERROR_FILENAME); - error_file = fopen(filename, "a"); + error_file = fopen(filename, MODE_APPEND); free(filename); return error_file; @@ -1326,7 +1340,7 @@ void dumpErrorFile() FILE *error_file; filename = getPath2(getUserDataDir(), ERROR_FILENAME); - error_file = fopen(filename, "r"); + error_file = fopen(filename, MODE_READ); free(filename); if (error_file != NULL)