⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 environ.c

📁 open arj source
💻 C
📖 第 1 页 / 共 5 页
字号:
}#endif/* Returns switch character used by OS */#ifdef REARJchar get_sw_char(){ #if TARGET==DOS  union REGS regs;  regs.x.ax=0x3700;  intdos(&regs, &regs);  return(regs.h.dl); #elif TARGET==OS2  return('/'); #else  return('-'); #endif}#endif/* Returns the amount of free space for disk on which the given file is   located. */#if SFX_LEVEL>=ARJSFXV||defined(REARJ)unsigned long file_getfree(char *name){ #if TARGET==DOS  #if COMPILER==BCC   struct dfree dtable;  #elif COMPILER==MSC   struct diskfree_t dtable;  #endif  char drive=0;  while(name[0]==' ')                   /* Skip over leading spaces, if any */   name++;  if(name[1]==':')   drive=toupper(name[0])-0x40;  #if COMPILER==BCC   getdfree(drive, &dtable);   if(dtable.df_sclus==65535)    return(MAXLONG);   else   {    return((LONG_MAX/((long)dtable.df_bsec*dtable.df_sclus)<dtable.df_avail)?           LONG_MAX:           (long)dtable.df_bsec*dtable.df_sclus*dtable.df_avail);   }  #elif COMPILER==MSC   if(_dos_getdiskfree((unsigned int)drive, &dtable))    return(ULONG_MAX);   else   {    return((LONG_MAX/((long)dtable.bytes_per_sector*dtable.sectors_per_cluster)<dtable.avail_clusters)?           LONG_MAX:           (long)dtable.bytes_per_sector*dtable.sectors_per_cluster*dtable.avail_clusters);   }  #endif #elif TARGET==OS2  USHORT drive=0;  FSALLOCATE fsinfo;  while(name[0]==' ')   name++;  if(name[1]==':')   drive=toupper(name[0])-0x40;  if(DosQFSInfo(drive, FSIL_ALLOC, (PBYTE)&fsinfo, sizeof(fsinfo)))   return(LONG_MAX);  else   return((LONG_MAX/(fsinfo.cSectorUnit*fsinfo.cbSector)<fsinfo.cUnitAvail)?          LONG_MAX:          fsinfo.cSectorUnit*fsinfo.cbSector*fsinfo.cUnitAvail); #elif TARGET==WIN32  char tmp[4], *ptmp=NULL;  DWORD bps, spclu, fclu, clu;  while(name[0]==' ')   name++;  if(name[1]==':')  {   ptmp=tmp;   tmp[0]=toupper(name[0]);   tmp[1]=':';   tmp[2]='\\';   tmp[3]='\0';  }  if(!GetDiskFreeSpace(ptmp, &spclu, &bps, &fclu, &clu))   return(LONG_MAX);  else   return((LONG_MAX/(spclu*bps)<fclu)?LONG_MAX:spclu*bps*fclu); #elif TARGET==UNIX  #if defined(__QNXNTO__)||defined(__sco__)||defined(SUNOS)   struct statvfs vfs;   if(statvfs(name, &vfs)==-1)    return(LONG_MAX);   return((LONG_MAX/512<vfs.f_bavail)?LONG_MAX:vfs.f_bavail*512);  #else   struct statfs sfs;   if(statfs(name, &sfs)==-1)    return(LONG_MAX);   return((LONG_MAX/512<sfs.f_bavail)?LONG_MAX:sfs.f_bavail*512);  #endif #endif}#endif/* findfirst() for external use */#if SFX_LEVEL>=ARJSFXVint file_find(char *name, struct file_properties *properties){ struct new_ffblk new_ffblk; int attrib=STD_FI_ATTRS; #if TARGET==UNIX  int u; #endif if(lfn_findfirst(name, &new_ffblk, attrib)!=0)  return(-1); else {  #if SFX_LEVEL>=ARJ   lfn_findclose(&new_ffblk);   finddata_to_properties(properties, &new_ffblk);  #else   properties->ftime=new_ffblk.ff_ftime;   properties->fsize=new_ffblk.ff_fsize;   properties->attrib=(ATTRIB)new_ffblk.ff_attrib;   #if TARGET!=UNIX    properties->type=(new_ffblk.ff_attrib&FATTR_DIREC)?ARJT_DIR:ARJT_BINARY;    properties->isarchive=(new_ffblk.ff_attrib&FATTR_ARCH)?1:0;   #else    u=uftype(new_ffblk.ff_attrib);    if(u&FATTR_DT_DIR)     properties->type=ARJT_DIR;    else if(u&FATTR_DT_UXSPECIAL)     properties->type=ARJT_UXSPECIAL;    else     properties->type=ARJT_BINARY;    properties->isarchive=1;    properties->l_search=new_ffblk.l_search;    properties->l_search.ref=0;    properties->islink=0;   #endif  #endif  return(0); }}#endif/* Returns the size of the given file */#if SFX_LEVEL>=ARJ||defined(REARJ)long file_getfsize(char *name){ #if SFX_LEVEL>=ARJ  struct new_ffblk new_ffblk;  int attrib=STD_FI_ATTRS;  if(lfn_findfirst(name, &new_ffblk, attrib)!=0)   return(0L);  else  {   lfn_findclose(&new_ffblk);    return(new_ffblk.ff_fsize);  } #else  FILE *stream;  long rc;  if((stream=file_open(name, m_rb))==NULL)   return(0);  #if TARGET!=UNIX   rc=filelength(fileno(stream));  #else   fseek(stream, 0L, SEEK_END);   rc=ftell(stream);  #endif  fclose(stream);  return(rc); #endif}#endif/* Returns last modification time for the given file */#if SFX_LEVEL>=ARJSFX||defined(REARJ)unsigned long file_getftime(char *name){ #if TARGET==DOS  #if SFX_LEVEL>=ARJSFXV   struct new_ffblk new_ffblk;   int attrib=STD_FI_ATTRS;   if(lfn_findfirst(name, &new_ffblk, attrib)!=0)    return(0L);   else   {    #if SFX_LEVEL>=ARJ     lfn_findclose(&new_ffblk);         /* Done automatically by ARJSFXV */    #endif    return(new_ffblk.ff_ftime);   }  #else   FILE *stream;   unsigned long rc;   if((stream=file_open(name, m_rb))==NULL)    return(0L);   #if COMPILER==BCC    getftime(fileno(stream), (struct ftime *)&rc);   #else    _dos_getftime(fileno(stream), (unsigned int *)&rc+1, (unsigned int *)&rc);   #endif   fclose(stream);   return(rc);  #endif #elif TARGET==OS2  HFILE hf;  #ifdef __32BIT__   ULONG action;  #else   USHORT action;  #endif  FILESTATUS fstatus;  if(DosOpen(name, &hf, &action, 0L, 0, FILE_OPEN, OPEN_ACCESS_READONLY|OPEN_SHARE_DENYNONE, 0L))   return(0L);  DosQFileInfo(hf, FIL_STANDARD, &fstatus, sizeof(fstatus));  DosClose(hf);  return(make_ftime(fstatus.fdateLastWrite, fstatus.ftimeLastWrite)); #elif TARGET==WIN32  FILETIME ftime, atime, ctime;  HANDLE hf;  if((hf=CreateFile(name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0))==INVALID_HANDLE_VALUE)   return(0L);  if(!GetFileTime(hf, &ctime, &atime, &ftime))   return(0L);  CloseHandle(hf);  return(dosify_time(&ftime)); #elif TARGET==UNIX  struct stat st;  if(lstat(name, &st)==-1)   return(0L);  return(st.st_mtime); #endif}#endif/* Queries the volume label for the specified drive. The destination buffer   will contain "" if the volume label is missing. */#if SFX_LEVEL>=ARJ&&defined(HAVE_VOL_LABELS)int file_getlabel(char *label, char drive, ATTRIB *attrib, unsigned long *ftime){ #if TARGET==DOS  struct new_ffblk new_ffblk;  char wildcard[10];  if(drive=='\0')   wildcard[0]='\0';  else  {   wildcard[0]=drive;   wildcard[1]=':';   wildcard[2]='\0';  }  strcat(wildcard, root_wildcard);  if(lfn_findfirst(wildcard, &new_ffblk, FATTR_LABEL))   return(0);                            /* Pretty incorrect but, if no files                                            are present, it won't be called */  if(_osmajor>2)  {   while(!(new_ffblk.ff_attrib&FATTR_LABEL))   {    if(!lfn_findnext(&new_ffblk))     return(0);   }   lfn_findclose(&new_ffblk);  }  strcpy(label, new_ffblk.ff_name);  *attrib=(ATTRIB)new_ffblk.ff_attrib;  *ftime=new_ffblk.ff_ftime;  return(0); #elif TARGET==OS2  FSINFO fsinfo;  USHORT rc;  rc=DosQFSInfo(drive=='\0'?0:drive-0x40, FSIL_VOLSER, (PBYTE)&fsinfo, sizeof(fsinfo));  if(rc)   return((rc==ERROR_NO_VOLUME_LABEL)?0:-1);  strcpy(label, fsinfo.vol.szVolLabel);  return(0); #elif TARGET==WIN32  DWORD dummy;  return(!GetVolumeInformation(NULL, label, CCHMAXPATH, NULL, &dummy, &dummy, NULL, 0)); #endif}#endif/* Read a line from the stdin w/echo, returning the number of bytes read. */#if SFX_LEVEL>=ARJSFX||defined(REARJ)int read_line(char *buf, int size){ #if TARGET==DOS  union REGS regs;  #if SFX_LEVEL>=ARJSFX||defined(REARJ)   char tmp_buf[160];                    /* Actually, DOS limit is 128 */  #endif  unsigned int ioctl_set, ioctl_isbinary, ioctl_response;  int chars_read;  int cchar;  regs.x.ax=0x4400;                      /* IOCTL - query device */  regs.x.bx=0;                           /* STDIN */  intdos(&regs, &regs);  ioctl_response=regs.x.dx;  ioctl_set=(ioctl_response&CHDI_SET)?1:0;  ioctl_isbinary=(ioctl_response&CHDI_BINARY)?1:0;  #ifdef REARJ   ioctl_isbinary=ioctl_set&ioctl_isbinary;  #endif  if(ioctl_set&&ioctl_isbinary||_osmajor<3)  {   #if SFX_LEVEL>=ARJSFXV    tmp_buf[0]=min(size, INPUT_LIMIT);   /* Number of input positions */    tmp_buf[1]=tmp_buf[0]-1;             /* Number of recallable positions */    regs.h.ah=0x0A;    regs.x.dx=(unsigned int)tmp_buf;    intdos(&regs, &regs);    chars_read=(int)tmp_buf[1];    if(tmp_buf[chars_read+2]=='\x0D')     tmp_buf[chars_read+2]='\0';         /* Convert to ASCIIZ */    strcpy(buf, tmp_buf+2);    nputlf();                            /* v 2.72+ fixup to live happily                                            under Unices */   #elif defined(REARJ)    tmp_buf[0]=min(size, INPUT_LIMIT);   /* Number of input positions */    cgets(tmp_buf);    chars_read=(int)tmp_buf[1];    strcpy(buf, tmp_buf+2);   #else    error(M_RAW_INPUT_REJECTED);   #endif  }  else  {   for(chars_read=0; (cchar=fgetc(stdin))!=EOF&&cchar!=LF; chars_read++)   {    if(chars_read<size-1)     buf[chars_read]=(char)cchar;   }   if(cchar==-1)    error(M_CANTREAD);   buf[chars_read]='\0';  }  msg_cprintf(0, cr);                   /* ASR fix 03/02/2003 for COLOR_OUTPUT */  return(chars_read); #elif (TARGET==OS2&&(COMPILER==MSC||defined(LIBC)))||TARGET==WIN32||TARGET==UNIX  int chars_read;  int cchar;  for(chars_read=0; (cchar=fgetc(stdin))!=EOF&&cchar!=LF; chars_read++)  {   if(chars_read<size-1)    buf[chars_read]=(char)cchar;  }  if(cchar==-1)   error(M_CANTREAD);  buf[chars_read]='\0';  return(chars_read); #else                          	/* A platform-neutral solution */  char *p;  #ifdef DEBUG   debug_report(dbg_cur_file, __LINE__, 'W');  #endif  fgets(buf, size, stdin);              /* DIRTY HACK */  if((p=strchr(buf, '\n'))!=NULL)   *p='\0';  if((p=strchr(buf, '\r'))!=NULL)   *p='\0';  return(strlen(buf)); #endif}#endif/* Returns file access mode in character format */#if SFX_LEVEL>=ARJSFXvoid get_mode_str(char *str, unsigned int mode){ #if TARGET==UNIX  int i;  str[0]='-';  for(i=0; i<3; i++)  {   str[(2-i)*3+1]=(mode&4)?'r':'-';   str[(2-i)*3+2]=(mode&2)?'w':'-';   str[(2-i)*3+3]=(mode&1)?'x':'-';   mode>>=3;  }  str[10]=' ';  str[11]=(mode&FATTR_SGID)?'G':'-';  str[12]=(mode&FATTR_SUID)?'U':'-';  str[13]=(mode&FATTR_SVTX)?'A':'-';  str[14]='\0'; #else  strcpy(str, attrib_buf);  if(mode&FATTR_ARCH)   str[0]='A';  if(mode&FATTR_SYSTEM)   str[1]='S';  if(mode&FATTR_HIDDEN)   str[2]='H';  if(mode&FATTR_RDONLY)   str[3]='R'; #endif}#endif/* Retrieves an environment string */#if TARGET==OS2&&SFX_LEVEL>=ARJSFXstatic char FAR *get_env_str(char *t){ #ifdef __32BIT__  PSZ rc;  if(DosScanEnv(t, &rc))   return(NULL);  return((char FAR *)rc); #else  USHORT selector;  USHORT cmd_offset;  char FAR *env_ptr;  int i;  DosGetEnv(&selector, &cmd_offset);  env_ptr=MAKEP(selector, 0);  while(*env_ptr!='\0')  {   for(i=0; t[i]!='\0'; i++)    if(env_ptr[i]=='\0'||env_ptr[i]!=t[i])     break;   if(t[i]=='\0'&&env_ptr[i]=='=')    return(env_ptr+i+1);   env_ptr+=i;   while(*env_ptr++!='\0');  }  return(NULL); #endif}#endif/* Reserves memory and gets an environment string */#if TARGET==OS2&&SFX_LEVEL>=ARJSFXchar *malloc_env_str(char *t){ char FAR *str, FAR *sptr; char *rc, *rptr; int i; if((str=get_env_str(t))==NULL)  return(NULL); i=1; for(sptr=str; *sptr!='\0'; sptr++)  i++; if((rc=(char *)malloc(i))==NULL)  return(NULL);                         /* Env. string was too long */ rptr=rc; for(sptr=str; *sptr!='\0'; sptr++)  *rptr++=*sptr; *rptr='\0'; return(rc);}#endif/* A small exported stub for C RTL to be happy */#if TARGET==OS2&&COMPILER==MSC&&SFX_LEVEL>=ARJchar *getenv(const char *str){ return(NULL);                          /* No such a string */}#endif/* Executes the given program directly, returning its RC */#if defined(REARJ)||(SFX_LEVEL>=ARJSFX&&TARGET==OS2)int exec_pgm(char *cmdline){ char tmp_cmd[CMDLINE_LENGTH+CCHMAXPATH]; #if TARGET==OS2                	/* && SFX_LEVEL>=ARJSFX */  char *params;  int p_pos;  #ifdef REARJ   #ifdef __32BIT__    PPIB ppib=NULL;    PTIB ptib=NULL;    ULONG child_pid, session_pid;    REQUESTDATA qr;    ULONG qrc;    ULONG cb_res;   #else    PID child_pid, session_pid;    PIDINFO pidi;    QUEUERESULT qr;    USHORT qrc;    USHORT cb_res;   #endif   STARTDATA sd;   char qname[CCHMAXPATH];   HQUEUE queue;   USHORT errcode;   PUSHORT res;   BYTE elem_priority;   char *argv[PARAMS_MAX];   int arg;   static char param_sep[]=" ";  #else   RESULTCODES rc;  #endif  #ifndef REARJ   memset(tmp_cmd, 0, sizeof(tmp_cmd));   if((params=strchr(cmdline, ' '))!=NULL)   {    p_pos=params-cmdline;    if(p_pos>0)     memcpy(tmp_cmd, cmdline, p_pos);    strcpy(tmp_cmd+p_pos+1, params);   }   else    strcpy(tmp_cmd, cmdline);   if(!DosExecPgm(NULL, 0, EXEC_SYNC, tmp_cmd, NULL, &rc, tmp_cmd))    r

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -