cpl/cpl_path.cpp
const char *CPLFormFilename( const char * pszPath,
                             const char * pszBasename,
                             const char * pszExtension )

{
    char *pszStaticResult = CPLGetStaticResult();
    const char  *pszAddedPathSep = "";
    const char  *pszAddedExtSep = "";

    if( pszPath == NULL )
        pszPath = "";
    else if( strlen(pszPath) > 0
             && pszPath[strlen(pszPath)-1] != '/'
             && pszPath[strlen(pszPath)-1] != '\\' )
        pszAddedPathSep = SEP_STRING;

    if( pszExtension == NULL )
        pszExtension = "";
    else if( pszExtension[0] != '.' && strlen(pszExtension) > 0 )
        pszAddedExtSep = ".";

    CPLAssert( strlen(pszPath) + strlen(pszAddedPathSep) +
               strlen(pszBasename) + strlen(pszAddedExtSep) +
               strlen(pszExtension) + 1 < CPL_PATH_BUF_SIZE );

    strncpy( pszStaticResult, pszPath, CPL_PATH_BUF_SIZE );
    strncat( pszStaticResult, pszAddedPathSep, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszBasename, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszAddedExtSep, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszExtension, CPL_PATH_BUF_SIZE);
    pszStaticResult[CPL_PATH_BUF_SIZE - 1] = '\0';

    return pszStaticResult;
}
/**
 * Build a full file path from a passed path, file basename and extension.
 *
 * The path, and extension are optional.  The basename may in fact contain
 * an extension if desired.
 *
 * <pre>
 * CPLFormFilename("abc/xyz","def", ".dat" ) == "abc/xyz/def.dat"
 * CPLFormFilename(NULL,"def", NULL ) == "def"
 * CPLFormFilename(NULL,"abc/def.dat", NULL ) == "abc/def.dat"
 * CPLFormFilename("/abc/xyz/","def.dat", NULL ) == "/abc/xyz/def.dat"
 * </pre>
 *
 * @param pszPath directory path to the directory containing the file.  This
 * may be relative or absolute, and may have a trailing path separator or
 * not.  May be NULL.
 *
 * @param pszBasename file basename.  May optionally have path and/or
 * extension.  May not be NULL. 
 *
 * @param pszExtension file extension, optionally including the period.  May
 * be NULL.
 *
 * @return a fully formed filename in an internal static string.  Do not
 * modify or free the returned string.  The string may be destroyed by the
 * next CPL call.
 */
Build a full file path from a passed path, file basename and extension.
The path, and extension are optional.  The basename may in fact contain
an extension if desired.



@param pszPath directory path to the directory containing the file.  This
may be relative or absolute, and may have a trailing path separator or
not.  May be NULL.

@param pszBasename file basename.  May optionally have path and/or
extension.  May not be NULL.

@param pszExtension file extension, optionally including the period.  May
be NULL.

@return a fully formed filename in an internal static string.  Do not
modify or free the returned string.  The string may be destroyed by the
next CPL call.
Build a full file path from a passed path file basename and extension . The path and extension are optional . The basename may in fact contain an extension if desired . @param pszPath directory path to the directory containing the file . This may be relative or absolute and may have a trailing path separator or not . May be NULL . @param pszBasename file basename . May optionally have path and / or extension . May not be NULL . @param pszExtension file extension optionally including the period . May be NULL . @return a fully formed filename in an internal static string . Do not modify or free the returned string . The string may be destroyed by the next CPL call .
const char *CPLFormFilename( const char * pszPath,
                             const char * pszBasename,
                             const char * pszExtension )
{
    char *pszStaticResult = CPLGetStaticResult();
    const char  *pszAddedPathSep = "";
    const char  *pszAddedExtSep = "";
    if( pszPath == NULL )
        pszPath = "";
    else if( strlen(pszPath) > 0
             && pszPath[strlen(pszPath)-1] != '/'
             && pszPath[strlen(pszPath)-1] != '\\' )
        pszAddedPathSep = SEP_STRING;
    if( pszExtension == NULL )
        pszExtension = "";
    else if( pszExtension[0] != '.' && strlen(pszExtension) > 0 )
        pszAddedExtSep = ".";
    CPLAssert( strlen(pszPath) + strlen(pszAddedPathSep) +
               strlen(pszBasename) + strlen(pszAddedExtSep) +
               strlen(pszExtension) + 1 < CPL_PATH_BUF_SIZE );
    strncpy( pszStaticResult, pszPath, CPL_PATH_BUF_SIZE );
    strncat( pszStaticResult, pszAddedPathSep, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszBasename, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszAddedExtSep, CPL_PATH_BUF_SIZE);
    strncat( pszStaticResult, pszExtension, CPL_PATH_BUF_SIZE);
    pszStaticResult[CPL_PATH_BUF_SIZE - 1] = '\0';
    return pszStaticResult;
}
const char * CPLFormFilename ( const char * pszPath , const char * pszBasename , const char * pszExtension ) { char * pszStaticResult = CPLGetStaticResult ( ) ; const char * pszAddedPathSep = " " ; const char * pszAddedExtSep = " " ; if ( pszPath == NULL ) pszPath = " " ; else if ( strlen ( pszPath ) > 0 && pszPath [ strlen ( pszPath ) - 1 ] != ' ' && pszPath [ strlen ( pszPath ) - 1 ] != ' \\ ' ) pszAddedPathSep = SEP_STRING ; if ( pszExtension == NULL ) pszExtension = " " ; else if ( pszExtension [ 0 ] != ' ' && strlen ( pszExtension ) > 0 ) pszAddedExtSep = " " ; CPLAssert ( strlen ( pszPath ) + strlen ( pszAddedPathSep ) + strlen ( pszBasename ) + strlen ( pszAddedExtSep ) + strlen ( pszExtension ) + 1 < CPL_PATH_BUF_SIZE ) ; strncpy ( pszStaticResult , pszPath , CPL_PATH_BUF_SIZE ) ; strncat ( pszStaticResult , pszAddedPathSep , CPL_PATH_BUF_SIZE ) ; strncat ( pszStaticResult , pszBasename , CPL_PATH_BUF_SIZE ) ; strncat ( pszStaticResult , pszAddedExtSep , CPL_PATH_BUF_SIZE ) ; strncat ( pszStaticResult , pszExtension , CPL_PATH_BUF_SIZE ) ; pszStaticResult [ CPL_PATH_BUF_SIZE - 1 ] = ' \0 ' ; return pszStaticResult ; }
Build a full file path from a passed path, file basename and extension.
Build a full file path from a passed path file basename and extension .