cpl/cpl_path.cpp
const char *CPLResetExtension( const char *pszPath, const char *pszExt )

{
    char    *pszStaticResult = CPLGetStaticResult();
    size_t  i;

/* -------------------------------------------------------------------- */
/*      First, try and strip off any existing extension.                */
/* -------------------------------------------------------------------- */
    strncpy( pszStaticResult, pszPath, CPL_PATH_BUF_SIZE );
    pszStaticResult[CPL_PATH_BUF_SIZE - 1] = '\0';
    for( i = strlen(pszStaticResult) - 1; i > 0; i-- )
    {
        if( pszStaticResult[i] == '.' )
        {
            pszStaticResult[i] = '\0';
            break;
        }

        if( pszStaticResult[i] == '/' || pszStaticResult[i] == '\\' 
            || pszStaticResult[i] == ':' )
            break;
    }

/* -------------------------------------------------------------------- */
/*      Append the new extension.                                       */
/* -------------------------------------------------------------------- */
    CPLAssert( strlen(pszExt) + 2 < CPL_PATH_BUF_SIZE );
    
    strcat( pszStaticResult, "." );
    strcat( pszStaticResult, pszExt );

    return pszStaticResult;
}
/**
 * Replace the extension with the provided one.
 *
 * @param pszPath the input path, this string is not altered.
 * @param pszExt the new extension to apply to the given path.
 *
 * @return an altered filename with the new extension.    Do not
 * modify or free the returned string.  The string may be destroyed by the
 * next CPL call.
 */
Replace the extension with the provided one.
@param pszPath the input path, this string is not altered.
@param pszExt the new extension to apply to the given path.

@return an altered filename with the new extension.    Do not
modify or free the returned string.  The string may be destroyed by the
next CPL call.
Replace the extension with the provided one . @param pszPath the input path this string is not altered . @param pszExt the new extension to apply to the given path . @return an altered filename with the new extension . Do not modify or free the returned string . The string may be destroyed by the next CPL call .
const char *CPLResetExtension( const char *pszPath, const char *pszExt )
{
    char    *pszStaticResult = CPLGetStaticResult();
    size_t  i;
    strncpy( pszStaticResult, pszPath, CPL_PATH_BUF_SIZE );
    pszStaticResult[CPL_PATH_BUF_SIZE - 1] = '\0';
    for( i = strlen(pszStaticResult) - 1; i > 0; i-- )
    {
        if( pszStaticResult[i] == '.' )
        {
            pszStaticResult[i] = '\0';
            break;
        }
        if( pszStaticResult[i] == '/' || pszStaticResult[i] == '\\' 
            || pszStaticResult[i] == ':' )
            break;
    }
    CPLAssert( strlen(pszExt) + 2 < CPL_PATH_BUF_SIZE );
    strcat( pszStaticResult, "." );
    strcat( pszStaticResult, pszExt );
    return pszStaticResult;
}
const char * CPLResetExtension ( const char * pszPath , const char * pszExt ) { char * pszStaticResult = CPLGetStaticResult ( ) ; size_t i ; strncpy ( pszStaticResult , pszPath , CPL_PATH_BUF_SIZE ) ; pszStaticResult [ CPL_PATH_BUF_SIZE - 1 ] = ' \0 ' ; for ( i = strlen ( pszStaticResult ) - 1 ; i > 0 ; i -- ) { if ( pszStaticResult [ i ] == ' ' ) { pszStaticResult [ i ] = ' \0 ' ; break ; } if ( pszStaticResult [ i ] == ' ' || pszStaticResult [ i ] == ' \\ ' || pszStaticResult [ i ] == ' ' ) break ; } CPLAssert ( strlen ( pszExt ) + 2 < CPL_PATH_BUF_SIZE ) ; strcat ( pszStaticResult , " " ) ; strcat ( pszStaticResult , pszExt ) ; return pszStaticResult ; }
Replace the extension with the provided one.
Replace the extension with the provided one .
/* -------------------------------------------------------------------- */ /*      First, try and strip off any existing extension.                */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /*      Append the new extension.                                       */ /* -------------------------------------------------------------------- */