id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
3199,Errors in FormatCRLF function to idrisi driver.,lucafibbi,ilucena,"The function FormatCRLF (in the file IdrisiDataset.cpp) creates a temporary file with the extension $$$ and the name equal to the rdc file. When the variable pszTempfile is calculated (with the name of the temporay file) even the variable pszFilename (with the name of the original rdc file) undergoes a change, so the rdc file can't be open, the temporary file remain open when the function return and the line feed of the rdc file remain unchanged.
Here, I show a possible solution of this bug:

original

void FormatCRLF( const char *pszFilename )
{
    const char *pszTempfile;
    FILE *fpIn;
    FILE *fpOut;
    char ch;

    char* pszFilenameDup = CPLStrdup( pszFilename );
    pszTempfile = CPLResetExtension( pszFilenameDup, ""$$$"" );
    CPLFree( pszFilenameDup );

    fpIn  = VSIFOpen( pszFilename, ""r"" );
    fpOut = VSIFOpen( pszTempfile, ""w"" );

    if ( fpIn == NULL )
    {
        return;
    }

    if ( fpOut == NULL )
    {
        VSIFClose( fpIn );
        return;
    }

    // Copy data

    ch = VSIFGetc( fpIn );

    while( VSIFEof( fpIn ) == FALSE )
    {
        VSIFPutc( ch, fpOut );
        ch = VSIFGetc( fpIn );
    }

    VSIFClose( fpIn );
    VSIFClose( fpOut );

    // Convert format

    fpIn  = VSIFOpen( pszTempfile, ""r"" );
    fpOut = VSIFOpen( pszFilename, ""w"" );

    if ( fpIn == NULL )
    {
        return;
    }

    if ( fpOut == NULL )
    {
        VSIFClose( fpIn );
        return;
    }

    ch = VSIFGetc( fpIn );

    while( VSIFEof( fpIn ) == FALSE )
    {
	if( ch == '\012' )
        {
            VSIFPutc( '\015', fpOut );
        }     
        VSIFPutc( ch, fpOut );
        ch = VSIFGetc( fpIn );
    }

    VSIFClose( fpIn );
    VSIFClose( fpOut );

    VSIUnlink( pszTempfile );    
}

new

void FormatCRLF( const char *pszFilename )
{
    char *pszTempfile = NULL;
    FILE *fpIn = NULL;
    FILE *fpOut = NULL;
    char ch;

    fpIn  = VSIFOpen( pszFilename, ""r"" );
    if ( fpIn == NULL )
    {
        return;
    }
    
	pszTempfile = (char *)CPLMalloc(strlen(pszFilename)+5);
	sprintf(pszTempfile,""%s.$$$"",pszFilename);
	
	fpOut = VSIFOpen( pszTempfile, ""w"" );
    if ( fpOut == NULL )
    {
		CPLFree( pszTempfile );
        VSIFClose( fpIn );
        return;
    }

    // Copy data

    ch = VSIFGetc( fpIn );

    while( VSIFEof( fpIn ) == FALSE )
    {
        VSIFPutc( ch, fpOut );
        ch = VSIFGetc( fpIn );
    }

    VSIFClose( fpIn );
    VSIFClose( fpOut );

    // Convert format

    fpIn  = VSIFOpen( pszTempfile, ""r"" );
    if ( fpIn == NULL )
    {
		CPLFree( pszTempfile );
        return;
    }
    fpOut = VSIFOpen( pszFilename, ""w"" );

    if ( fpOut == NULL )
    {
		CPLFree( pszTempfile );
        VSIFClose( fpIn );
        return;
    }

    ch = VSIFGetc( fpIn );

    while( VSIFEof( fpIn ) == FALSE )
    {
	if( ch == '\012' )
        {
            VSIFPutc( '\015', fpOut );
        }     
        VSIFPutc( ch, fpOut );
        ch = VSIFGetc( fpIn );
    }

    VSIFClose( fpIn );
    VSIFClose( fpOut );

    VSIUnlink( pszTempfile );    
	CPLFree( pszTempfile );
}

",defect,closed,normal,,GDAL_Raster,1.6.2,normal,fixed,Idrisi Raster,warmerdam
