cpl/cpl_path.cpp
const char *CPLGetDirname( 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 the dot will be
 * returned.  It is the only difference from CPLGetPath().
 *
 * <pre>
 * CPLGetDirname( "abc/def.xyz" ) == "abc"
 * CPLGetDirname( "/abc/def/" ) == "/abc/def"
 * CPLGetDirname( "/" ) == "/"
 * CPLGetDirname( "/abc/def" ) == "/abc"
 * CPLGetDirname( "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 the dot will be
returned.  It is the only difference from CPLGetPath().



@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 the dot will be returned . It is the only difference from CPLGetPath () . @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 *CPLGetDirname( 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 * CPLGetDirname ( 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 .