"Fossies" - the Fresh Open Source Software Archive

Member "tofrodos/src/emsg.c" (27 Oct 2013, 1470 Bytes) of archive /linux/misc/tofrodos-1.7.13.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "emsg.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     emsg.c      Error message printing functions.
    3     Copyright (c) 2005-2012 by Christopher Heng. All rights reserved.
    4 
    5 */
    6 
    7 /* this should always be first */
    8 #include "config.h"
    9 
   10 /* standard headers */
   11 #include <stdarg.h> /* va_arg and family */
   12 #include <stdio.h>  /* fprintf(), fopen(), fclose() */
   13 #include <stdlib.h> /* atexit() */
   14 
   15 /* our own headers */
   16 #include "emsg.h"
   17 #include "tofrodos.h"
   18 
   19 /* macros */
   20 #if defined(MSDOS) || (WINDOWS)
   21 #define ERROR_LOG_MODE  "at"
   22 #else
   23 #define ERROR_LOG_MODE  "a"
   24 #endif
   25 
   26 /* data local to this file */
   27 static FILE * errorfp ;
   28 
   29 /* local functions */
   30 static void close_error_file ( void ) ;
   31 
   32     
   33 void emsg ( char * message, ... )
   34 {
   35     va_list argp ;
   36 
   37     if (errorfp == NULL) {
   38         if (errorlogfilename == NULL) {
   39             errorfp = stderr ;
   40         }
   41         else {
   42             errorfp = fopen ( errorlogfilename, ERROR_LOG_MODE );
   43             if (errorfp == NULL) {
   44                 fprintf( stderr, EMSG_ERRORLOG, progname, errorlogfilename );
   45                 errorfp = stderr ;
   46             }
   47             else {
   48                 /* close error file on exit (not needed, but just being pedantically neat) */
   49                 atexit( close_error_file ); /* ignore errors */
   50             }
   51         }   
   52     }
   53     fprintf( errorfp, "%s: ", progname );
   54     va_start( argp, message );
   55     vfprintf( errorfp, message, argp );
   56     va_end( argp );
   57     return ;
   58 }
   59 
   60 static void close_error_file ( void )
   61 {
   62     /* there's no need to check for stderr, since we should not have set this function */
   63     /* on exit() if only stderr were used */
   64     if (errorfp != NULL) {
   65         fclose( errorfp );
   66     }
   67     return ;
   68 }