示例#1
0
unsigned LocalSetFileAttr( char *name, long attr )
/********************************************/
{
    FILESTATUS3 fileinfo;

    if ( DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ) )
        return -1;

    fileinfo.attrFile = attr;
    return( StashErrCode( DosSetPathInfo( name, FIL_STANDARD,
        &fileinfo, sizeof( fileinfo ) , 0), OP_LOCAL ) );
}
示例#2
0
error_handle LocalSetFileAttr( const char *name, long attr )
/**********************************************************/
{
#if 0
    FILESTATUS3 fileinfo;

    if ( DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ) )
        return -1;

    fileinfo.attrFile = attr;
    return( StashErrCode( DosSetPathInfo( name, FIL_STANDARD,
        &fileinfo, sizeof( fileinfo ) , 0), OP_LOCAL ) );
#else
    name=name;attr=attr;
    return 0;
#endif
}
示例#3
0
error_handle LocalSetFileAttr( const char *name, long attr )
/**********************************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosSetFileMode( name, attr, 0 ), OP_LOCAL ) );
#else
    FILESTATUS3 fileinfo;
    APIRET      rc;

    rc = DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) );
    if( rc == 0 ) {
        fileinfo.attrFile = attr;
        rc = DosSetPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ), 0 );
    }
    return( StashErrCode( rc, OP_LOCAL ) );
#endif
}
示例#4
0
文件: ea.c 项目: pgul/lgate
int _ea_write (char *path, int handle, PFEA2LIST src)
{
  ULONG rc;
  EAOP2 eaop;

  eaop.fpGEA2List = NULL;
  eaop.fpFEA2List = src;
  eaop.oError = 0;
  if (path != NULL)
    rc = DosSetPathInfo (path, 2, &eaop, sizeof (eaop), 0);
  else
    rc = DosSetFileInfo (handle, 2, &eaop, sizeof (eaop));
  if (rc != 0)
    {
      _ea_set_errno (rc);
      return -1;
    }
  return 0;
}
示例#5
0
_WCRTLINK unsigned _dos_setfileattr( const char *path, unsigned attribute )
{
    APIRET  rc;

#if defined(__WARP__)
    FILESTATUS3     fs;

    rc = DosQueryPathInfo( (PSZ)path, FIL_STANDARD, &fs, sizeof( fs ) );
    if( rc == 0 ) {
        fs.attrFile = attribute;
        rc = DosSetPathInfo( (PSZ)path, FIL_STANDARD, &fs, sizeof( fs ), 0 );
    }
#else
    rc = DosSetFileMode( (PSZ)path, attribute, 0ul );
#endif
    if( rc ) {
        return( __set_errno_dos_reterr( rc ) );
    }
    return( 0 );
}
示例#6
0
_WCRTLINK int __F_NAME(chmod,_wchmod)( const CHAR_TYPE *pathname, int pmode )
{
    APIRET      rc;
    OS_UINT     attr;
#ifndef _M_I86
    FILESTATUS3 fs;
#endif
#ifdef __WIDECHAR__
    char        mbPath[MB_CUR_MAX * _MAX_PATH];

    if( wcstombs( mbPath, pathname, sizeof( mbPath ) ) == -1 ) {
        mbPath[0] = '\0';
    }
#endif
#ifdef _M_I86
    rc = DosQFileMode( (PSZ)__F_NAME(pathname,mbPath), &attr, 0 );
#else
    rc = DosQueryPathInfo( (PSZ)__F_NAME(pathname,mbPath), FIL_STANDARD,
                           &fs, sizeof( fs ) );
    attr = fs.attrFile;
#endif
    if( rc != 0 ) {
        return( __set_errno_dos( rc ) );
    }
    attr &= ~_A_RDONLY;
    if( !( pmode & S_IWRITE ) ) {
        attr |= _A_RDONLY;
    }
#ifdef _M_I86
    rc = DosSetFileMode( (PSZ)__F_NAME(pathname,mbPath), attr, 0 );
#else
    fs.attrFile = attr;
    rc = DosSetPathInfo( (PSZ)__F_NAME(pathname,mbPath), FIL_STANDARD,
                           &fs, sizeof( fs ), 0 );
#endif
    if( rc != 0 ) {
        return( __set_errno_dos( rc ) );
    }
    return( 0 );
}
示例#7
0
APIRET DeleteFile (PSZ          pszPath,
                   FILEFINDBUF3 *pFileInfo)
{
  APIRET     rc = NO_ERROR;                                /* API-Returncode */
  ULONG      ulAgeCurrent;             /* canonical file are of current file */
  FDATE      fdAgeCurrent;                             /* filedate structure */
  FILESTATUS fStat;                   /* filestatus structure for attributes */
  int        iAnswer;             /* user answer on the confirmation request */
  CHAR       szFileNameBuffer[MAXPATHLEN];         /* buffer for DosEditName */
  FILESTATUS3 fs3;   /* filestatus level 3 information from DosQueryPathInfo */
  CHAR       szFileDate[32];                     /* buffer for the file date */
  CHAR       szFileAttr[6];                /* buffer for the file attributes */
  CHAR       szTokenizerBuffer[MAXPATHLEN];               /* i hate strtok ! */

  if (!Options.fsDontDeleteFiles)              /* if we have to remove files */
  {
                                                            /* check for age */
    if (Options.fsFileAge)                 /* deletion selective on file age */
    {
      if (Options.fsFileAgeWrite)
      {
        fdAgeCurrent = pFileInfo->fdateLastWrite;
        ulAgeCurrent = ToolsDateToAge(fdAgeCurrent.day,
                                      fdAgeCurrent.month,
                                      fdAgeCurrent.year + 1980);
      }
      else
        if (Options.fsFileAgeAccess)
        {
          fdAgeCurrent = pFileInfo->fdateLastAccess;
          ulAgeCurrent = ToolsDateToAge(fdAgeCurrent.day,
                                   fdAgeCurrent.month,
                                   fdAgeCurrent.year + 1980);
        }
        else
          if (Options.fsFileAgeCreate)
          {
            fdAgeCurrent = pFileInfo->fdateCreation;
            ulAgeCurrent = ToolsDateToAge(fdAgeCurrent.day,
                                 fdAgeCurrent.month,
                                 fdAgeCurrent.year + 1980);
          }
          else
          {
                                     /* none specified, take last-write date */
            fdAgeCurrent = pFileInfo->fdateLastWrite;
            ulAgeCurrent = ToolsDateToAge(fdAgeCurrent.day,
                                     fdAgeCurrent.month,
                                     fdAgeCurrent.year + 1980);
          }

                                         /* now check if it is to be deleted */
      if (Options.fsFileAgeNewer)
      {
        if (ulAgeCurrent < Globals.ulFileDate)
          return (NO_ERROR);               /* abort processing for this file */
      }
      else
      {
        if (ulAgeCurrent > Globals.ulFileDate)
          return (NO_ERROR);               /* abort processing for this file */
      }
    }


                                            /* check with the file name mask */
    if (Options.fsFileNameMask)
    {
      PSZ  pszToken;  /* string pointer points to file token within filemask */
      BOOL fMatch;                         /* match - true, no match - false */

      strcpy (szTokenizerBuffer,                /* strtok is a real PITA !!! */
              Options.pszFileNameMask);

      pszToken = strtok(szTokenizerBuffer,                  /* tokenize this */
                        ",");
      fMatch   = FALSE;                               /* this is the default */

      while ( (pszToken != NULL) && /* as long as there is a name to process */
              (fMatch   == FALSE) )                /* and no match was found */
      {
        rc = DosEditName(1,                /* use OS/2 1.2 editing semantics */
                         pFileInfo->achName,                /* source string */
                         pszToken,                         /* editing string */
                         szFileNameBuffer,              /* local name buffer */
                         sizeof (szFileNameBuffer));        /* buffer length */
        if (rc != NO_ERROR)                              /* check for errors */
          return (rc);                              /* raise error condition */

        if (stricmp(pFileInfo->achName,     /* check if filename has changed */
                    szFileNameBuffer) == 0)
          fMatch = TRUE;                       /* the same, abort processing */

        pszToken = strtok(NULL,                    /* skip to the next token */
                          ",");
      }

      if (fMatch == FALSE)                           /* no match was found ! */
        return (NO_ERROR);                  /* then go not beyond this point */
    }


    StrFAttrToStringShort (pFileInfo->attrFile,        /* map the attributes */
                           szFileAttr);

    StrFDateTimeToString (pFileInfo->fdateLastWrite,   /* map the date       */
                          pFileInfo->ftimeLastWrite,
                          szFileDate);

    if (Options.fsSimulation)                    /* simulate deletion only ? */
      printf ("\n  %9u %s %s %s",
              pFileInfo->cbFile,
              szFileAttr,
              szFileDate,
              pFileInfo->achName);
    else
    {
      if (Options.fsVerbose ||                           /* verbose output ? */
          Options.fsShowFiles ||
          Options.fsConfirmationPrompt)
        printf ("\n  %9u %s %s %s",
                pFileInfo->cbFile,
                szFileAttr,
                szFileDate,
                pFileInfo->achName);

      if (Options.fsConfirmationPrompt)       /* prompt for every deletion ? */
      {
        iAnswer = ToolsConfirmationQuery();                  /* ask the user */
        switch (iAnswer)
        {
          case 0:                                                      /* no */
            return (NO_ERROR);                           /* abort processing */

          case 1:                                                     /* yes */
            break;                                           /* continue ... */

          case 2:                                                  /* escape */
            exit (1);                     /* PH: urgs, terminate the process */
        }
      }


      if (Options.fsForceDelete)
        rc = DosForceDelete(pszPath);        /* file will not be recoverable */
      else
        rc = DosDelete(pszPath);                  /* OK, remove that thing ! */

      if ( (rc == ERROR_ACCESS_DENIED) &&             /* check for READ-ONLY */
          Options.fsRemoveAttributes)
      {
        rc = DosQueryPathInfo (pszPath,            /* query file information */
                               FIL_STANDARD,
                               &fStat,
                               sizeof(fStat));
        if (rc != NO_ERROR)                              /* check for errors */
          return (rc);                              /* raise error condition */

        fStat.attrFile = FILE_NORMAL;                /* reset the attributes */

        rc = DosSetPathInfo (pszPath,                 /* set the information */
                             FIL_STANDARD,
                             &fStat,
                             sizeof(fStat),
                             0L);
        if (rc != NO_ERROR)                              /* check for errors */
          return (rc);                              /* raise error condition */

                                                            /* now try again */
        if (Options.fsForceDelete)
          rc = DosForceDelete(pszPath);      /* file will not be recoverable */
        else
          rc = DosDelete(pszPath);                /* OK, remove that thing ! */
      }
    }

    if (rc == NO_ERROR)             /* if the file has actually been deleted */
    {
      Globals.ulDeletedBytes += pFileInfo->cbFile;
      Globals.ulDeletedAlloc += pFileInfo->cbFileAlloc;
      Globals.ulFilesDeleted++;                     /* update the statistics */
    }
  }

  return (rc);                                                         /* ok */
}
示例#8
0
APIRET DeleteDir (PSZ pszPath)
{
  APIRET rc = NO_ERROR;                                    /* API-Returncode */
  int    iAnswer;                /* answer from the user confirmation prompt */
  FILESTATUS fStat;                   /* filestatus structure for attributes */

  Globals.ulDirectoriesScanned++;                   /* update the statistics */

  if (!Options.fsDontDeleteDirs)             /* if we have to remove subdirs */
  {
                                                     /* remove the directory */
    if (Options.fsSimulation)                    /* simulate deletion only ? */
      printf ("\n  rd %s",
              pszPath);
    else
    {
      if (Options.fsVerbose ||                           /* verbose output ? */
          Options.fsConfirmationPrompt)
        printf ("\nRemoving %s ",
                pszPath);

      if (Options.fsConfirmationPrompt)       /* prompt for every deletion ? */
      {
        iAnswer = ToolsConfirmationQuery();                  /* ask the user */
        switch (iAnswer)
        {
          case 0:                                                      /* no */
            return (NO_ERROR);                           /* abort processing */

          case 1:                                                     /* yes */
            break;                                           /* continue ... */

          case 2:                                                  /* escape */
            exit (1);                     /* PH: urgs, terminate the process */
        }
      }

      rc = DosDeleteDir(pszPath);                 /* OK, remove that thing ! */
      if ( (rc == ERROR_ACCESS_DENIED) &&             /* check for READ-ONLY */
          Options.fsRemoveAttributes)
      {
        rc = DosQueryPathInfo (pszPath,            /* query file information */
                               FIL_STANDARD,
                               &fStat,
                               sizeof(fStat));
        if (rc == NO_ERROR)                              /* check for errors */
        {
          fStat.attrFile = FILE_NORMAL;              /* reset the attributes */
          rc = DosSetPathInfo (pszPath,               /* set the information */
                               FIL_STANDARD,
                               &fStat,
                               sizeof(fStat),
                               0L);
          if (rc == NO_ERROR)                            /* check for errors */                                                            /* now try again */
            rc = DosDeleteDir(pszPath);           /* OK, remove that thing ! */
        }
      }

      if (rc == NO_ERROR)                                /* check for errors */
        Globals.ulDirectoriesDeleted++;             /* update the statistics */
    }
  }

  return (rc);                                                         /* ok */
}
int EditAttributes (FILES *f) {

  char  *buf;
  USHORT len = (vio.col * 7) * 2,curpos = 0;
  char   nattr = (1 << 4) | (7 | 8);
  char   sattr = 8;
  int    ret = 0,x,key;
  BOOL   okay = TRUE;
  char   attrs[5] = "----";

  if(!f)
    return -1;
  buf = malloc(len);
  if(!buf)
    return -1;

  ThreadMsg(" ");

  VioReadCellStr(buf,&len,(vio.row / 2) - 1,0,0);

  VioWrtCharStrAtt("ÚÄ Attributes: Ä¿",17,(vio.row / 2) - 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Readonly: [ ] ³",17,vio.row / 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Hidden:   [ ] ³",17,(vio.row / 2) + 1,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ System:   [ ] ³",17,(vio.row / 2) + 2,
                   34,&nattr,0);
  VioWrtCharStrAtt("³ Archived: [ ] ³",17,(vio.row / 2) + 3,
                   34,&nattr,0);
  VioWrtCharStrAtt("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ",17,(vio.row / 2) + 4,
                   34,&nattr,0);
  VioWrtNAttr(&sattr,1,vio.row / 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 1,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 2,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 3,51,0);
  VioWrtNAttr(&sattr,1,(vio.row / 2) + 4,51,0);
  VioWrtNAttr(&sattr,16,(vio.row / 2) + 5,36,0);
  if(f->attrFile & FILE_READONLY)
    attrs[0] = 'x';
  if(f->attrFile & FILE_HIDDEN)
    attrs[1] = 'x';
  if(f->attrFile & FILE_SYSTEM)
    attrs[2] = 'x';
  if(f->attrFile & FILE_ARCHIVED)
    attrs[3] = 'x';
  for(x = 0;x < 4;x++)
    VioWrtCharStr(attrs + x,1,x + (vio.row / 2),47,0);
  VioSetCurPos(curpos + (vio.row / 2),47,0);
  ShowCursor(FALSE);
  while(okay) {
    VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
    VioSetCurPos(curpos + (vio.row / 2),47,0);
    key = get_ch(-1);
    switch(key) {
      case 256:
        break;

      case 45 | 256:
      case 61 | 256:
      case '\x1b':  /* abort */
        okay = FALSE;
        ret = -1;
        break;

      case '\r':      /* process */
        okay = FALSE;
        {
          FILESTATUS3 fs3;

          if(!DosQueryPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3))) {
            fs3.attrFile &= (~FILE_DIRECTORY);
            if(attrs[0] == 'x')
              fs3.attrFile |= FILE_READONLY;
            else
              fs3.attrFile &= (~FILE_READONLY);
            if(attrs[1] == 'x')
              fs3.attrFile |= FILE_HIDDEN;
            else
              fs3.attrFile &= (~FILE_HIDDEN);
            if(attrs[2] == 'x')
              fs3.attrFile |= FILE_SYSTEM;
            else
              fs3.attrFile &= (~FILE_SYSTEM);
            if(attrs[3] == 'x')
              fs3.attrFile |= FILE_ARCHIVED;
            else
              fs3.attrFile &= (~FILE_ARCHIVED);
            if(DosSetPathInfo(f->filename,FIL_STANDARD,&fs3,sizeof(fs3),
                              DSPI_WRTTHRU))
              DosBeep(50,100);
            else
              ret = 1;
          }
          else
            DosBeep(50,100);
        }
        break;

      case 72 | 256:  /* up */
        curpos--;
        if(curpos > 3)
          curpos = 3;
        break;

      case 'x':
      case 'X':
      case '+':
        attrs[curpos] = 'x';
        break;

      case '-':
        attrs[curpos] = '-';
        break;

      case ' ':       /* toggle */
        attrs[curpos] = (attrs[curpos] == 'x') ? '-' : 'x';
        VioWrtCharStr(attrs + curpos,1,curpos + (vio.row / 2),47,0);
        /* intentional fallthru */
      case 80 | 256:  /* down */
        curpos++;
        if(curpos > 3)
          curpos = 0;
        break;
    }
  }

  ShowCursor(TRUE);
  VioWrtCellStr(buf,len,(vio.row / 2) - 1,0,0);
  free(buf);
  SetupConsole();
  ThreadMsg(NULL);
  return ret;
}
示例#10
0
文件: mzip.c 项目: ggargano/hbtest2
static int hb_unzipExtractCurrentFile( unzFile hUnzip, const char * szFileName, const char * szPassword )
{
   char          szName[ HB_PATH_MAX ];
   HB_SIZE       nPos, nLen;
   char          cSep, * pString;
   unz_file_info ufi;
   int        iResult;
   HB_FHANDLE hFile;

   iResult = unzGetCurrentFileInfo( hUnzip, &ufi, szName, HB_PATH_MAX - 1,
                                    NULL, 0, NULL, 0 );
   if( iResult != UNZ_OK )
      return iResult;

   iResult = unzOpenCurrentFilePassword( hUnzip, szPassword );

   if( iResult != UNZ_OK )
      return iResult;

   if( szFileName )
      hb_strncpy( szName, szFileName, sizeof( szName ) - 1 );

   nLen = strlen( szName );

   /* Test shows that files in subfolders can be stored to zip file without
      explicitly adding folder. So, let's create a required path */

   nPos = 1;
   while( nPos < nLen )
   {
      cSep = szName[ nPos ];

      /* allow both path separators, ignore terminating path separator */
      if( ( cSep == '\\' || cSep == '/' ) && nPos < nLen - 1 )
      {
         szName[ nPos ] = '\0';
         hb_fsMkDir( szName );
         szName[ nPos ] = cSep;
      }
      nPos++;
   }

   if( ufi.external_fa & 0x40000000 ) /* DIRECTORY */
   {
      hb_fsMkDir( szName );
      iResult = UNZ_OK;
   }
   else
   {
      hFile = hb_fsCreate( szName, FC_NORMAL );

      if( hFile != FS_ERROR )
      {
         pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE );

         while( ( iResult = unzReadCurrentFile( hUnzip, pString, HB_Z_IOBUF_SIZE ) ) > 0 )
            hb_fsWriteLarge( hFile, pString, ( HB_SIZE ) iResult );

         hb_xfree( pString );

#if defined( HB_OS_WIN )
         {
            FILETIME   ftutc, ft;
            SYSTEMTIME st;

            st.wSecond       = ( WORD ) ufi.tmu_date.tm_sec;
            st.wMinute       = ( WORD ) ufi.tmu_date.tm_min;
            st.wHour         = ( WORD ) ufi.tmu_date.tm_hour;
            st.wDay          = ( WORD ) ufi.tmu_date.tm_mday;
            st.wMonth        = ( WORD ) ufi.tmu_date.tm_mon + 1;
            st.wYear         = ( WORD ) ufi.tmu_date.tm_year;
            st.wMilliseconds = 0;

            if( SystemTimeToFileTime( &st, &ft ) &&
                LocalFileTimeToFileTime( &ft, &ftutc ) )
            {
               SetFileTime( ( HANDLE ) hb_fsGetOsHandle( hFile ), &ftutc, &ftutc, &ftutc );
            }
         }
#endif

         hb_fsClose( hFile );
      }
      else
         iResult = -200 - hb_fsError();
   }
   unzCloseCurrentFile( hUnzip );

#if defined( HB_OS_WIN )
   {
      LPTSTR  lpFileNameFree;
      LPCTSTR lpFileName = HB_FSNAMECONV( szName, &lpFileNameFree );

      SetFileAttributes( ( LPCTSTR ) lpFileName, ufi.external_fa & 0xFF );

      if( lpFileNameFree )
         hb_xfree( lpFileNameFree );
   }
#elif defined( HB_OS_UNIX ) || defined( __DJGPP__ )
   {
      struct utimbuf utim;
      struct tm      st;
      time_t         tim;

      char *       pszFree;
      const char * szNameOS = hb_fsNameConv( szName, &pszFree );

#  if defined( __DJGPP__ )
      _chmod( szNameOS, 1, ufi.external_fa & 0xFF );
#  else
      HB_FATTR ulAttr = ufi.external_fa;

      if( ( ulAttr & 0xFFFF0000 ) == 0 )
         ulAttr = hb_translateExtAttr( szName, ulAttr );

      chmod( szNameOS,
             ( ( ulAttr & 0x00010000 ) ? S_IXOTH : 0 ) |
             ( ( ulAttr & 0x00020000 ) ? S_IWOTH : 0 ) |
             ( ( ulAttr & 0x00040000 ) ? S_IROTH : 0 ) |
             ( ( ulAttr & 0x00080000 ) ? S_IXGRP : 0 ) |
             ( ( ulAttr & 0x00100000 ) ? S_IWGRP : 0 ) |
             ( ( ulAttr & 0x00200000 ) ? S_IRGRP : 0 ) |
             ( ( ulAttr & 0x00400000 ) ? S_IXUSR : 0 ) |
             ( ( ulAttr & 0x00800000 ) ? S_IWUSR : 0 ) |
             ( ( ulAttr & 0x01000000 ) ? S_IRUSR : 0 ) );
#  endif
      memset( &st, 0, sizeof( st ) );

      st.tm_sec  = ufi.tmu_date.tm_sec;
      st.tm_min  = ufi.tmu_date.tm_min;
      st.tm_hour = ufi.tmu_date.tm_hour;
      st.tm_mday = ufi.tmu_date.tm_mday;
      st.tm_mon  = ufi.tmu_date.tm_mon;
      st.tm_year = ufi.tmu_date.tm_year - 1900;

      tim = mktime( &st );
#  if defined( HB_HAS_LOCALTIME_R )
      gmtime_r( &tim, &st );
#  else
      st = *gmtime( &tim );
#  endif
      utim.actime = utim.modtime = mktime( &st );

      utime( szNameOS, &utim );

      if( pszFree )
         hb_xfree( pszFree );
   }
#elif defined( HB_OS_DOS )
   {
#  if defined( __RSX32__ ) || defined( __GNUC__ )
      char * pszFree;

      _chmod( hb_fsNameConv( szName, &pszFree ), 1, ufi.external_fa & 0xFF );

      if( pszFree )
         hb_xfree( pszFree );
#  else
      hb_fsSetAttr( szName, ufi.external_fa & 0xFF );
#  endif
   }

#elif defined( HB_OS_OS2 )
   {
      FILESTATUS3 fs3;
      APIRET      ulrc;
      HB_FATTR    ulAttr = FILE_NORMAL;
      int         iAttr  = ufi.external_fa & 0xFF;

      char *       pszFree;
      const char * szNameOS = hb_fsNameConv( szName, &pszFree );

      if( iAttr & HB_FA_READONLY )
         ulAttr |= FILE_READONLY;
      if( iAttr & HB_FA_HIDDEN )
         ulAttr |= FILE_HIDDEN;
      if( iAttr & HB_FA_SYSTEM )
         ulAttr |= FILE_SYSTEM;
      if( iAttr & HB_FA_ARCHIVE )
         ulAttr |= FILE_ARCHIVED;

      ulrc = DosQueryPathInfo( ( PCSZ ) szNameOS, FIL_STANDARD, &fs3, sizeof( fs3 ) );

      if( ulrc == NO_ERROR )
      {
         FDATE fdate;
         FTIME ftime;

         fdate.year    = ufi.tmu_date.tm_year - 1980;
         fdate.month   = ufi.tmu_date.tm_mon;
         fdate.day     = ufi.tmu_date.tm_mday;
         ftime.hours   = ufi.tmu_date.tm_hour;
         ftime.minutes = ufi.tmu_date.tm_min;
         ftime.twosecs = ufi.tmu_date.tm_sec / 2;

         fs3.attrFile = ulAttr;

         fs3.fdateCreation = fs3.fdateLastAccess = fs3.fdateLastWrite = fdate;
         fs3.ftimeCreation = fs3.ftimeLastAccess = fs3.ftimeLastWrite = ftime;
         ulrc = DosSetPathInfo( ( PCSZ ) szNameOS, FIL_STANDARD,
                                &fs3, sizeof( fs3 ), DSPI_WRTTHRU );
      }

      if( pszFree )
         hb_xfree( pszFree );
   }
#else
   {
      hb_fsSetAttr( szName, ufi.external_fa );
   }
#endif

   return iResult;
}
示例#11
0
文件: ea_mgr.c 项目: OPSF/uClinux
int set_ea(char FAR *i_eas, char *name)
{
 #ifdef HAVE_EAS
  int rc=0;
  char FAR *eas;
  unsigned int i, total;
  #if TARGET==OS2
   #ifdef __32BIT__
    FILESTATUS4 fs;
    EAOP2 eaop;
    char FAR *real_pfeal;
    PFEA2LIST pfeal;
    PFEA2 pf, opf;
   #else
    EAOP eaop;
    PFEALIST pfeal;
    PFEA pf;
    FILESTATUS2 fs;
    SEL selector;
   #endif
  #elif TARGET==WIN32
   PFEALIST pfeal0, pfeal;
   PFEA pf;
   struct nt_sid *sid;
   unsigned char *pstreambuf, *streambuf;
   WIN32_STREAM_ID w32sid;
   unsigned long stream_len;
  #endif

  eas=i_eas;
  if(discard_ea(name))
   return(-1);
  if((total=mget_word(eas))==0)
   return(0);
  #if TARGET==OS2
   #ifdef __32BIT__
    /* This takes the 4-byte prefixes into account (are the V1.2 EAs still
       valid if they flow beyond 64K when the oNextEntryOffset is applied?).
       Also, we ensure that it is aligned properly. In theory, there may be
       a way to crash this (72K doesn't consider the multitude of EAs) but we
       don't know/care about it -- ASR 17/10/2000 */
    real_pfeal=(char FAR *)farmalloc_msg(73728);
    pfeal=(PFEA2LIST)align_dword(real_pfeal);
    eaop.fpFEA2List=pfeal;
   #else
    if(DosAllocSeg(65535U, &selector, SEG_NONSHARED))
     return(-1);
    pfeal=(PFEALIST)MAKEP(selector, 0);
    eaop.fpFEAList=pfeal;
   #endif
  #elif TARGET==WIN32
   pstreambuf=(char *)farmalloc_msg(65536+260*total);
   pfeal=pfeal0=(PFEALIST)(streambuf=align_dword(pstreambuf));
  #endif
  eas+=2;
  pf=&pfeal->list[0];
  for(i=0; i<total; i++)
  {
   #if TARGET==OS2&&defined(__32BIT__)
    opf=pf;
   #endif
   #if TARGET==WIN32
    pf=&pfeal->list[0];
   #endif
   pf->fEA=mget_byte(eas++);
   pf->cbName=mget_byte(eas++);
   pf->cbValue=mget_word(eas);
   eas+=2;
   #if TARGET==OS2&&defined(__32BIT__)
     far_memmove((char FAR *)pf+sizeof(FEA2)-1, eas, pf->cbName);
     *((char FAR *)pf+sizeof(FEA2)-1+pf->cbName)='\0';
   #else /* Win32 or OS/2-16 */
     far_memmove((char FAR *)pf+sizeof(FEA), eas, pf->cbName);
     *((char FAR *)pf+sizeof(FEA)+pf->cbName)='\0';
   #endif
   eas+=pf->cbName;
   #if TARGET==OS2&&defined(__32BIT__)
    far_memmove((char FAR *)pf+sizeof(FEA2)+pf->cbName, eas, pf->cbValue);
   #else /* Win32 or OS/2-16 */
    far_memmove((char FAR *)pf+sizeof(FEA)+pf->cbName+1, eas, pf->cbValue);
   #endif
   eas+=pf->cbValue;
   #if SFX_LEVEL>=ARJ
    #if TARGET==OS2&&defined(__32BIT__)
     if(ea_filter((char FAR *)pf+sizeof(FEA2), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas))
    #else /* Win32 or OS/2-16 */
     if(ea_filter((char FAR *)pf+sizeof(FEA), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas))
    #endif
   #endif
   /* Update the offsets */
   #if TARGET==OS2
    #ifdef __32BIT__
     pf=(PFEA2)((char FAR *)pf+sizeof(FEA2)+pf->cbName+pf->cbValue);
    #else
     pf=(PFEA)((char FAR *)pf+sizeof(FEA)+pf->cbName+1+pf->cbValue);
    #endif
    /* Align at DWORD boundary and issue the list fixups */
    #ifdef __32BIT__
     pf=(PFEA2)align_dword((char FAR *)pf);
     opf->oNextEntryOffset=(i+1==total)?0:(char FAR *)pf-(char FAR *)opf;
    #endif
   #elif TARGET==WIN32
    pfeal=(PFEALIST)((char FAR *)pfeal+sizeof(FEALIST)+pf->cbName+1+pf->cbValue);
    if(i<total-1)
     pfeal=(PFEALIST)align_dword((char FAR*)pfeal);
    pfeal0->cbList=(i==total-1)?
                   0:
                   (((char FAR *)pfeal)-((char FAR *)pfeal0));
    pfeal0=pfeal;
   #endif
  }
  #if TARGET==OS2
   pfeal->cbList=(char FAR *)pf-(char FAR *)pfeal;
   #ifdef __32BIT__
    rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0);
    farfree(real_pfeal);
   #else
    rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0, 0L);
    DosFreeSeg(selector);
   #endif
   if(!rc)
   {
    #ifdef __32BIT__
     if(DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs)))
    #else
     if(DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L))
    #endif
     rc=-1;
    else
     if(fs.cbList<=4)
      rc=-1;
   }
  #elif TARGET==WIN32
   if((sid=open_streams(name, 1))==NULL)
    rc=-1;
   else
   {
    memset(&w32sid, 0, sizeof(w32sid));
    w32sid.dwStreamId=BACKUP_EA_DATA;
    w32sid.Size.LowPart=stream_len=(((char FAR *)pfeal)-streambuf);
    if(create_stream(&w32sid, sid)||write_stream(streambuf, stream_len, sid)<stream_len)
     rc=-1;
    close_streams(sid);
   }
   free(pstreambuf);
  #endif
  return(rc);
 #else
  return(-1);
 #endif
}
示例#12
0
文件: ea_mgr.c 项目: OPSF/uClinux
int discard_ea(char *name)
{
 #if TARGET==OS2
  ULONG count;
  #ifdef __32BIT__
   APIRET rc;
   char FAR *real_pfeal;
   PFEA2LIST pfeal;
   EAOP2 eaop;
   PDENA2 pdena;
  #else
   USHORT rc;
   PFEALIST pfeal;
   EAOP eaop;
   PDENA1 pdena;
  #endif
  int rcode=0;

  #ifdef __32BIT__
   pdena=(PDENA2)farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
   real_pfeal=(char FAR *)farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
   pfeal=(PFEA2LIST)align_dword(real_pfeal);
  #else
   pdena=(PDENA1)farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
   pfeal=(PFEALIST)farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
  #endif
  while(1)
  {
   count=1L;
   #ifdef __32BIT__
    if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, 1L, (PVOID)pdena,
                        sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                        ENUMEA_LEVEL_NO_VALUE))
   #else
    if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, 1L, (PVOID)pdena,
                        sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                        ENUMEA_LEVEL_NO_VALUE, 0L))
   #endif
    break;
   if(count==0L)
    break;
   /* EA (pdena->szName) consumes (pdena->cbValue) bytes */
   #ifdef __32BIT__
    eaop.fpFEA2List=pfeal;
    pfeal->list[0].oNextEntryOffset=0;
   #else
    eaop.fpFEAList=pfeal;
   #endif
   pfeal->list[0].fEA=0;
   pfeal->list[0].cbName=far_strlen(pdena->szName);
   pfeal->list[0].cbValue=0;
   #ifdef __32BIT__
    far_strcpy((char FAR *)&(pfeal->list[0])+sizeof(FEA2)-1, pdena->szName);
    pfeal->cbList=(unsigned long)sizeof(FEA2LIST)+pfeal->list[0].cbName;
    if((rc=DosSetPathInfo(name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0))!=0)
    {
     rcode=-1;
     break;
    }
   #else
    far_strcpy((char FAR *)&(pfeal->list[0])+sizeof(FEA), pdena->szName);
    pfeal->cbList=(unsigned long)sizeof(FEALIST)+pfeal->list[0].cbName+1;
    if((rc=DosSetPathInfo(name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0, 0L))!=0)
    {
     rcode=-1;
     break;
    }
   #endif
  }
  farfree(pdena);
  #ifndef TILED
   farfree(real_pfeal);
  #endif
  return(rcode);
 #elif TARGET==WIN32
  /* There seems to be no easy way to not purge EAs using the backup APIs! */
  return(0);
 #else
  return(-1);
 #endif
}