Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
931 B
2
Indexable
Never
static FILE* LogFileRename(
	FILE* LogFilePtr,
	char* LogName,
	char* DirName
)
{
	char	Path[ _MAX_PATH ];
	char	Base[ _MAX_PATH ];

	int		Error;


	if( LogFilePtr )
	{
		SplitFileName( LogName, Path, Base );
		strcat( Path, DirName );
		MKDIR( Path );
		strcat( Path, "\\" );
		strcat( Path, Base );
		fclose( LogFilePtr );
		LogPrintf( LOG_INFO, "LogRename: %s -> %s\n", LogName, Path );
		if( rename( LogName, Path ) )
		{
			Error = errno;
			LogPrintf( LOG_INFO | LOG_ERRLOG, "LogRename: %s -> %s\n", LogName, Path );
			LogPrintf( LOG_INFO | LOG_ERRLOG, "\t%s\n", strerror( Error ) );
			return NULL;
		}
		LogFilePtr = fopen( LogName, "at" );
		if( LogFilePtr == NULL )
		{
			Error = errno;
			LogPrintf( LOG_INFO | LOG_ERRLOG, "LogRename: unable to open %s\n", LogName );
			LogPrintf( LOG_INFO | LOG_ERRLOG, "\t%s\n", strerror( Error ) );
			return NULL;
		}
	}
	return LogFilePtr;
}
Leave a Comment