X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flibgame%2Fmisc.c;h=e144979a7bb40ed1c2a38132e7860629477041ff;hb=681721dddc91bcdaef50002d1e861cc8d484e938;hp=2947adc4b000dc36a85a867908559b56e424492d;hpb=3d07b68a314ce189f207e42d95f786979662410d;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 2947adc4..e144979a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1,14 +1,14 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1994-2001 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* misc.c * +* misc.c * ***********************************************************/ #include @@ -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)