Пример #1
0
BOOL hb_spFile( BYTE * pFilename, BYTE * pRetPath )
{
   BYTE *Path;
   BOOL bIsFile = FALSE;
   PHB_FNAME pFilepath;

   HB_TRACE(HB_TR_DEBUG, ("hb_spFile(%s, %p)", (char*) pFilename, pRetPath));

   if( pRetPath )
   {
      Path = pRetPath;
   }
   else
   {
      Path = (BYTE *) hb_xgrab( _POSIX_PATH_MAX + 1 );
   }

   pFilepath = hb_fsFNameSplit( (char*) pFilename );

   if( pFilepath->szPath )
   {
      hb_fsFNameMerge( (char*) Path, pFilepath );
      bIsFile = hb_fsFile( Path );
   }
   else
   {
      char * szDefault = hb_set.HB_SET_DEFAULT;
      if( szDefault )
      {
         pFilepath->szPath = szDefault;
         hb_fsFNameMerge( (char*) Path, pFilepath );
         bIsFile = hb_fsFile( Path );
      }

      if( !bIsFile && hb_set.HB_SET_PATH )
      {
         HB_PATHNAMES *NextPath = hb_setGetFirstSetPath();

         while( bIsFile == FALSE && NextPath )
         {
            pFilepath->szPath = NextPath->szPath;
            hb_fsFNameMerge( (char*) Path, pFilepath );
            bIsFile = hb_fsFile( Path );
            NextPath = NextPath->pNext;
         }
      }

      /*
       * This code is intentional. To eliminate race condition,
       * in pending hb_spCreate()/hb_spOpen() call when we have to know
       * real path and file name we have to set its deterministic value
       * here. If it's not necessary the caller may drop this value.
       */
      if( ! bIsFile )
      {
         pFilepath->szPath = szDefault ? szDefault : ( char * ) ".";
         hb_fsFNameMerge( (char*) Path, pFilepath );
      }
   }

   hb_xfree( pFilepath );

   if( pRetPath == NULL )
   {
      hb_xfree( Path );
   }

   return bIsFile;
}
Пример #2
0
HB_BOOL hb_spFile( const char * pszFileName, char * pszRetPath )
{
   char * pszPath;
   HB_BOOL bIsFile = HB_FALSE;
   PHB_FNAME pFilepath;

   HB_TRACE( HB_TR_DEBUG, ( "hb_spFile(%s, %p)", pszFileName, pszRetPath ) );

   if( pszRetPath )
      pszPath = pszRetPath;
   else
      pszPath = ( char * ) hb_xgrab( HB_PATH_MAX );

   pFilepath = hb_fsFNameSplit( pszFileName );

   if( pFilepath->szPath )
   {
      hb_fsFNameMerge( pszPath, pFilepath );
      bIsFile = hb_fsFile( pszPath );
   }
   else
   {
      const char * szDefault = hb_setGetDefault();
      if( szDefault )
      {
         pFilepath->szPath = szDefault;
         hb_fsFNameMerge( pszPath, pFilepath );
         bIsFile = hb_fsFile( pszPath );
      }

      if( ! bIsFile && hb_setGetPath() )
      {
         HB_PATHNAMES * pNextPath = hb_setGetFirstSetPath();

         while( bIsFile == HB_FALSE && pNextPath )
         {
            pFilepath->szPath = pNextPath->szPath;
            hb_fsFNameMerge( pszPath, pFilepath );
            bIsFile = hb_fsFile( pszPath );
            pNextPath = pNextPath->pNext;
         }
      }

      /*
       * This code is intentional. To eliminate race condition,
       * in pending hb_spCreate()/hb_spOpen() call when we have to know
       * real path and file name we have to set its deterministic value
       * here. If it's not necessary the caller may drop this value.
       */
      if( ! bIsFile )
      {
         pFilepath->szPath = szDefault ? szDefault : ".";
         hb_fsFNameMerge( pszPath, pFilepath );
      }
   }

   hb_xfree( pFilepath );

   if( pszRetPath == NULL )
      hb_xfree( pszPath );

   return bIsFile;
}