cpl/cpl_path.cpp
const char *CPLGetPath( const char *pszFilename )

{
    int         iFileStart = CPLFindFilenameStart(pszFilename);
    char       *pszStaticResult = CPLGetStaticResult();

    CPLAssert( iFileStart < CPL_PATH_BUF_SIZE );

    if( iFileStart == 0 )
    {
        strcpy( pszStaticResult, "" );
        return pszStaticResult;
    }

    strncpy( pszStaticResult, pszFilename, iFileStart );
    pszStaticResult[iFileStart] = '\0';

    if( iFileStart > 1
        && (pszStaticResult[iFileStart-1] == '/'
            || pszStaticResult[iFileStart-1] == '\\') )
        pszStaticResult[iFileStart-1] = '\0';

    return pszStaticResult;
}
/**
 * Extract directory path portion of filename.
 *
 * Returns a string containing the directory path portion of the passed
 * filename.  If there is no path in the passed filename an empty string
 * will be returned (not NULL).
 *
 * <pre>
 * CPLGetPath( "abc/def.xyz" ) == "abc"
 * CPLGetPath( "/abc/def/" ) == "/abc/def"
 * CPLGetPath( "/" ) == "/"
 * CPLGetPath( "/abc/def" ) == "/abc"
 * CPLGetPath( "abc" ) == ""
 * </pre>
 *
 * @param pszFilename the filename potentially including a path.
 *
 *  @return Path in an internal string which must not be freed.  The string
 * may be destroyed by the next CPL filename handling call.  The returned
 * will generally not contain a trailing path separator.
 */
Extract directory path portion of filename.
Returns a string containing the directory path portion of the passed
filename.  If there is no path in the passed filename an empty string
will be returned (not NULL).



@param pszFilename the filename potentially including a path.

@return Path in an internal string which must not be freed.  The string
may be destroyed by the next CPL filename handling call.  The returned
will generally not contain a trailing path separator.
Extract directory path portion of filename . Returns a string containing the directory path portion of the passed filename . If there is no path in the passed filename an empty string will be returned ( not NULL ) . @param pszFilename the filename potentially including a path . @return Path in an internal string which must not be freed . The string may be destroyed by the next CPL filename handling call . The returned will generally not contain a trailing path separator .
const char *CPLGetPath( const char *pszFilename )
{
    int         iFileStart = CPLFindFilenameStart(pszFilename);
    char       *pszStaticResult = CPLGetStaticResult();
    CPLAssert( iFileStart < CPL_PATH_BUF_SIZE );
    if( iFileStart == 0 )
    {
        strcpy( pszStaticResult, "" );
        return pszStaticResult;
    }
    strncpy( pszStaticResult, pszFilename, iFileStart );
    pszStaticResult[iFileStart] = '\0';
    if( iFileStart > 1
        && (pszStaticResult[iFileStart-1] == '/'
            || pszStaticResult[iFileStart-1] == '\\') )
        pszStaticResult[iFileStart-1] = '\0';
    return pszStaticResult;
}
const char * CPLGetPath ( const char * pszFilename ) { int iFileStart = CPLFindFilenameStart ( pszFilename ) ; char * pszStaticResult = CPLGetStaticResult ( ) ; CPLAssert ( iFileStart < CPL_PATH_BUF_SIZE ) ; if ( iFileStart == 0 ) { strcpy ( pszStaticResult , " " ) ; return pszStaticResult ; } strncpy ( pszStaticResult , pszFilename , iFileStart ) ; pszStaticResult [ iFileStart ] = ' \0 ' ; if ( iFileStart > 1 && ( pszStaticResult [ iFileStart - 1 ] == ' ' || pszStaticResult [ iFileStart - 1 ] == ' \\ ' ) ) pszStaticResult [ iFileStart - 1 ] = ' \0 ' ; return pszStaticResult ; }
Extract directory path portion of filename.
Extract directory path portion of filename .