/* ======================================================================================= Name : LogFile.cpp Author : vincent lhullier Date :27/07/97 Description : implement function to write in a log file MngData operation ======================================================================================= Modification -> Author : Date : Description : ======================================================================================= */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include #include /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* * put this line in comment if you don't want log file generation */ #define __LOGFILE__ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* ======================================================================================= CONSTANTS ======================================================================================= */ /* * Name of log file */ #define C_szLogFile "MngData.Log" /* ======================================================================================= GLOBALS ======================================================================================= */ char g_szLogFileFullName[MAX_PATH]; /* ======================================================================================= FUNCTIONS ======================================================================================= */ /* --------------------------------------------------------------------------------------- Description : initialize full name of log file, create it if it does'nt exist --------------------------------------------------------------------------------------- */ void LOG_fn_vInitLogFile( void ) { #ifdef __LOGFILE__ GetCurrentDirectory( MAX_PATH, g_szLogFileFullName ); if (g_szLogFileFullName[ strlen( g_szLogFileFullName ) - 1 ] != '\\' ) strcat( g_szLogFileFullName, "\\" ); strcat( g_szLogFileFullName, C_szLogFile ); if ( _access( g_szLogFileFullName, 0 ) != 0) { // if file doesn't exist create it FILE *hpFile; hpFile = fopen( g_szLogFileFullName, "wt" ); if (hpFile == NULL) ::MessageBox( NULL, "Unable to create Log file", "Warning", MB_OK ); else fclose( hpFile ); } #endif //__LOGFILE__ } /* --------------------------------------------------------------------------------------- Description : delete log file --------------------------------------------------------------------------------------- */ void LOG_fn_vDeleteLogFile( void ) { #ifdef __LOGFILE__ remove( C_szLogFile ); #endif //__LOGFILE__ } /* --------------------------------------------------------------------------------------- Description : write data in log file szBuffer -> data to write in Log File Returns (long ) number of bytes written in file --------------------------------------------------------------------------------------- */ long LOG_fn_lWriteInLogFile( char *szBuffer ) { #ifdef __LOGFILE__ long lWrite; FILE *hpFile; hpFile = fopen( g_szLogFileFullName, "at"); if (hpFile == NULL) return 0; lWrite = fwrite( szBuffer, 1, strlen( szBuffer ), hpFile ); fclose ( hpFile ); return lWrite; #endif //__LOGFILE__ }