diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 1c697ce9b7..9fca86c12a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,16 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-11-04 03:40 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * include/hbapifs.h + * harbour/source/common/hbfsapi.c + ! fixed hb_fsFileExists() for DOS + + Added hb_fsDirExists() + + * include/hbextern.ch + * source/rtl/hbfile.c + + Added HB_DIREXISTS() + 2007-11-04 02:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/source/common/hbstr.c diff --git a/harbour/include/hbapifs.h b/harbour/include/hbapifs.h index c2ada6d05a..9b3fe9fb56 100644 --- a/harbour/include/hbapifs.h +++ b/harbour/include/hbapifs.h @@ -148,6 +148,7 @@ extern HB_EXPORT FHANDLE hb_fsGetOsHandle( FHANDLE hFileHandle ); extern HB_EXPORT USHORT hb_fsGetFError ( void ); /* get FERROR() flag */ extern HB_EXPORT void hb_fsSetFError ( USHORT uiError ); /* set FERROR() flag */ extern HB_EXPORT BOOL hb_fsFileExists ( const char * pszFileName ); /* check if a file exists (wildcard chars not accepted). */ +extern HB_EXPORT BOOL hb_fsDirExists ( const char * pszDirName ); /* check if a directory exists (wildcard chars not accepted). */ #define hb_fsFLock( h, s, l ) hb_fsLock( h, s, l, FL_LOCK ) #define hb_fsFUnlock( h, s, l ) hb_fsLock( h, s, l, FL_UNLOCK ) diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index 328a55822d..c3a2785bd4 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -781,6 +781,7 @@ EXTERNAL HB_COMPILER EXTERNAL HB_PCODEVER EXTERNAL HB_BUILDDATE EXTERNAL HB_FILEEXISTS +EXTERNAL HB_DIREXISTS EXTERNAL HB_FNAMEMERGE EXTERNAL HB_FNAMESPLIT EXTERNAL HB_LANGNAME diff --git a/harbour/source/common/hbfsapi.c b/harbour/source/common/hbfsapi.c index 12ec9bde4c..d585f6b1e6 100644 --- a/harbour/source/common/hbfsapi.c +++ b/harbour/source/common/hbfsapi.c @@ -300,7 +300,7 @@ HB_EXPORT BOOL hb_fsFileExists( const char * pszFileName ) HB_DOS_INT86X( 0x21, ®s, ®s, &sregs ); - fExist = regs.x.cflag == 0; + fExist = regs.x.cflag == 0 && ( regs.HB_XREGS.cx & 10h ) == 0; } #elif defined( HB_OS_WIN_32 ) { @@ -331,3 +331,58 @@ HB_EXPORT BOOL hb_fsFileExists( const char * pszFileName ) return fExist; } + + +HB_EXPORT BOOL hb_fsDirExists( const char * pszDirName ) +{ + BOOL fExist; + BOOL fFree; + + HB_TRACE(HB_TR_DEBUG, ("hb_fsDirExists(%p)", pszDirName)); + + if( pszDirName == NULL ) + return FALSE; + + pszDirName = ( char * ) hb_fsNameConv( ( BYTE * ) pszDirName, &fFree ); + +#if defined( HB_OS_DOS ) + { + union REGS regs; + struct SREGS sregs; + + regs.HB_XREGS.ax = 0x4300; + regs.HB_XREGS.dx = FP_OFF( pszDirName ); + sregs.ds = FP_SEG( pszDirName ); + + HB_DOS_INT86X( 0x21, ®s, ®s, &sregs ); + + fExist = regs.x.cflag == 0 && ( regs.HB_XREGS.cx & 10h ); + } +#elif defined( HB_OS_WIN_32 ) + { + DWORD dwAttr; + + dwAttr = GetFileAttributesA( pszDirName ); + fExist = ( dwAttr != INVALID_FILE_ATTRIBUTES ) && + ( dwAttr & FILE_ATTRIBUTE_DIRECTORY ); + } +#elif defined( HB_OS_UNIX ) + { + struct stat statbuf; + + fExist = stat( pszDirName, &statbuf ) == 0 && + S_ISDIR( statbuf.st_mode ); + } +#else + { + int TODO; /* To force warning */ + + fExist = FALSE; + } +#endif + + if( fFree ) + hb_xfree( ( void * ) pszDirName ); + + return fExist; +} diff --git a/harbour/source/rtl/hbfile.c b/harbour/source/rtl/hbfile.c index 77f6f60a44..10feff8fad 100644 --- a/harbour/source/rtl/hbfile.c +++ b/harbour/source/rtl/hbfile.c @@ -57,3 +57,8 @@ HB_FUNC( HB_FILEEXISTS ) { hb_retl( hb_fsFileExists( hb_parc( 1 ) ) ); } + +HB_FUNC( HB_DIREXISTS ) +{ + hb_retl( hb_fsDirExists( hb_parc( 1 ) ) ); +}