예제 #1
0
파일: uxspec.c 프로젝트: vadimG2015i/Cplus
static char FAR *fill_hdr_size(char FAR *dest, int type, int size)
{
 if(size<UXSB_SIZE_THRESHOLD)
 {
  mput_byte(MK_UXSB(type, size), dest);
  return(dest+1);
 }
 else
 {
  mput_byte(MK_UXSB(type, UXSB_SIZE_THRESHOLD), dest);
  mput_word(size, dest+1);
  return(dest+3);
 }
}
예제 #2
0
파일: uxspec.c 프로젝트: vadimG2015i/Cplus
int query_uxspecial(char FAR **dest, char *name, struct file_properties *props)
{
 #if TARGET==UNIX
  struct stat st;
  char tmp_name[FILENAME_MAX-1];
  int l;
  char FAR *dptr;
  int hardlink=0;

  if(lstat(name, &st)==-1)
   return(-1);
  if(!S_ISDIR(st.st_mode)&&st.st_nlink>1&&props->islink)
   hardlink=1;
  if(S_ISFIFO(st.st_mode))
   mput_byte(MK_UXSB(UXSB_FIFO, 0), (*dest=(char FAR *)farmalloc_msg(1)));
  else if(S_ISLNK(st.st_mode)||hardlink)
  {
   if(hardlink)
   {
    retrieve_entry(tmp_name, NULL, &flist_main, props->hl_search.ref);
    l=strlen(tmp_name);
   }
   else
   {
    if((l=readlink(name, tmp_name, sizeof(tmp_name)))<=0)
     return(-1);
   }
   *dest=(char FAR *)farmalloc_msg(UXSB_CALC_SIZE(l));
   dptr=fill_hdr_size(*dest, hardlink?UXSB_HLNK:UXSB_LNK, l);
   far_memmove(dptr, (char FAR *)tmp_name, l);
  }
  else if(S_ISCHR(st.st_mode)||S_ISBLK(st.st_mode))
  {
   *dest=(char FAR *)farmalloc_msg(UXSB_CALC_SIZE(sizeof(st.st_rdev)));
   dptr=fill_hdr_size(*dest, S_ISCHR(st.st_mode)?UXSB_CHR:UXSB_BLK, sizeof(st.st_rdev));
   far_memmove(dptr, (char FAR *)&st.st_rdev, sizeof(st.st_rdev));
  }
  else
   return(-1);                          /* Unusual file type, report warning */
 #else
  return(-1);
 #endif
 return(0);
}
예제 #3
0
파일: ea_mgr.c 프로젝트: OPSF/uClinux
int query_ea(char FAR **dest, char *name, int skip_ln)
{
 #ifdef HAVE_EAS
  ULONG count, j;
  #if TARGET==OS2
   #ifdef __32BIT__
    EAOP2 eaop;
    PGEA2LIST pgeal;
    PFEA2LIST pfeal;
    APIRET rc;
    PDENA2 pdena;
    FILESTATUS4 fs;
   #else
    EAOP eaop;
    PGEALIST pgeal;
    PFEALIST pfeal;
    USHORT rc;
    PDENA1 pdena;
    FILESTATUS2 fs;
   #endif
  #elif TARGET==WIN32
   struct nt_sid *sid;
   unsigned char *streambuf;
   unsigned long stream_len;
   PFEALIST pfeal;
  #endif
  int rcode=0;
  char FAR *dptr, FAR *nptr;

  #if TARGET==OS2
   pdena=farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
   #ifdef __32BIT__
    pgeal=(PGEA2LIST)farmalloc_msg(sizeof(GEA2LIST)+CCHMAXPATHCOMP);
    if(DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs)))
     return(-1);
   #else
    pgeal=(PGEALIST)farmalloc_msg(sizeof(GEALIST)+CCHMAXPATHCOMP);
    if(DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L))
     return(-1);
   #endif
   if(fs.cbList<4)
    fs.cbList=4;                         /* Fix for Ext2FS */
   /* Allocate enough space to hold EA block */
   #ifdef __32BIT__
    *dest=(char FAR *)farmalloc_msg((int)fs.cbList*2); /* SDK does recommend it */
   #else
    *dest=(char FAR *)farmalloc_msg((int)fs.cbList-2);
   #endif
  #elif TARGET==WIN32
   if((sid=open_streams(name, 0))==NULL)
    return(-1);
   stream_len=seek_stream_id(BACKUP_EA_DATA, sid);
   if(stream_len==0||stream_len>65535)
   {
    close_streams(sid);
    *dest=(char FAR *)farmalloc_msg(2);
    dptr=*dest;
    mput_word(0, dptr);
    return(0);
   }
   /* It's a plain FEALIST, so doesn't require much caution */
   streambuf=(char FAR *)farmalloc_msg((int)stream_len);
   *dest=(char FAR *)farmalloc_msg((int)stream_len);
   if((stream_len=read_stream(streambuf, stream_len, sid))==0)
   {
    close_streams(sid);
    dptr=*dest;
    mput_word(0, dptr);
    free(streambuf);
    return(0);
   }
  #endif
  /* Initialize storage */
  dptr=*dest;
  mput_word(0, dptr);
  dptr+=2;
  j=0L;
  while(1)
  {
   #if TARGET==OS2
    count=1L;
    #ifdef __32BIT__
     if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, ++j, (PVOID)pdena,
                         sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                         ENUMEA_LEVEL_NO_VALUE))
      break;
    #else
     if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, ++j, (PVOID)pdena,
                         sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                         ENUMEA_LEVEL_NO_VALUE, 0L))
      break;
    #endif
    if(count==0L)
     break;
    /* EA (pdena->szName) consumes (pdena->cbValue) bytes */
    #ifdef __32BIT__
     eaop.fpGEA2List=pgeal;
    #else
     eaop.fpGEAList=pgeal;
    #endif
    far_strcpy(pgeal->list[0].szName, pdena->szName);
    pgeal->list[0].cbName=pdena->cbName;
    #ifdef __32BIT__
     pgeal->list[0].oNextEntryOffset=0;
     pgeal->cbList=sizeof(GEA2LIST)+pdena->cbName;
     eaop.fpGEA2List=pgeal;
     pfeal=(PFEA2LIST)farmalloc_msg(sizeof(FEA2LIST)+pdena->cbName+pdena->cbValue+1);
     pfeal->cbList=sizeof(FEA2LIST)+pdena->cbName+pdena->cbValue+1;
     eaop.fpFEA2List=pfeal;
     if((rc=DosQueryPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop)))!=0)
     {
      farfree(pfeal);
      rcode=-1;
      break;
     }
     nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA2)-1;
    #else
     pgeal->cbList=sizeof(GEALIST)+pdena->cbName;
     eaop.fpGEAList=pgeal;
     pfeal=(PFEALIST)farmalloc_msg(sizeof(FEALIST)+pdena->cbName+pdena->cbValue+1);
     pfeal->cbList=sizeof(FEALIST)+pdena->cbName+pdena->cbValue+1;
     eaop.fpFEAList=pfeal;
     if((rc=DosQPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop), 0L))!=0)
     {
      farfree(pfeal);
      rcode=-1;
      break;
     }
     nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA);
    #endif
   #elif TARGET==WIN32
    /* Win32 provides us with a FEALIST at our disposal. */
    pfeal=(PFEALIST)streambuf;
    nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA);
   #endif
  #if SFX_LEVEL>=ARJ
   if(ea_filter(nptr, skip_ln)&&((pfeal->list[0].fEA&FEA_NEEDEA)||!crit_eas))
  #endif
   {
    mput_word(mget_word(*dest)+1, *dest);
    mput_byte(pfeal->list[0].fEA, dptr++);
    mput_byte(pfeal->list[0].cbName, dptr++);
    mput_word(pfeal->list[0].cbValue, dptr);
    dptr+=2;
    far_memmove(dptr, nptr, (int)pfeal->list[0].cbName);
    dptr+=pfeal->list[0].cbName;
    far_memmove(dptr, nptr+pfeal->list[0].cbName+1, pfeal->list[0].cbValue);
    dptr+=pfeal->list[0].cbValue;
   }
   #if TARGET==OS2
    farfree(pfeal);
   #elif TARGET==WIN32
    if(pfeal->cbList==0)                /* Indicates the last EA */
     break;
    streambuf+=pfeal->cbList;
   #endif
  }
  #if TARGET==OS2
   farfree(pdena);
   farfree(pgeal);
  #endif
  #if TARGET==WIN32
   close_streams(sid);
  #endif
  return(rcode);
 #else
  return(-1);
 #endif
}