📄 environ.c
字号:
ds->da_mon=st.wMonth; #else time_t t; struct tm *tms; t=time(NULL); tms=localtime(&t); ds->da_year=tms->tm_year+1900; ds->da_day=tms->tm_mday; ds->da_mon=tms->tm_mon+1; #endif}#endif/* Gets address of DOS DTA */#if SFX_LEVEL>=ARJSFXV&&COMPILER!=BCC&&TARGET==DOSstatic char FAR *getdta(){ union REGS regs; struct SREGS sregs; regs.h.ah=0x2F; intdosx(®s, ®s, &sregs); return(MK_FP(sregs.es, regs.x.bx));}#endif/* Sets address of DOS DTA */#if SFX_LEVEL>=ARJSFXV&&COMPILER!=BCC&&TARGET==DOSstatic void setdta(char FAR *dta){ union REGS regs; struct SREGS sregs; regs.h.ah=0x1A; sregs.ds=FP_SEG(dta); regs.x.dx=FP_OFF(dta); intdosx(®s, ®s, &sregs);}#endif/* * OS/2 farcalloc()/farfree() routines */#if TARGET==OS2&&defined(TILED)/* farcalloc() for 0-based segments */#if SFX_LEVEL>=ARJ&&defined(ASM8086)void FAR *farcalloc_based(unsigned long num, unsigned long size){ USHORT total; SEL selector; void FAR *rc; total=(USHORT)num*size; if(DosAllocSeg(total, &selector, SEG_NONSHARED)) return(NULL); rc=(void FAR *)MAKEP(selector, 0); far_memset(rc, 0, total); return(rc);}#endif/* farfree() for 0-based segments */#if SFX_LEVEL>=ARJ&&defined(ASM8086)void farfree_based(void FAR *ptr){ DosFreeSeg(SELECTOROF(ptr));}#endif#endif/* Sets the process priority. */#if TARGET!=DOS&&SFX_LEVEL>=ARJvoid set_priority(struct priority *priority){ #if TARGET==OS2 DosSetPrty(PRTYS_THREAD, priority->class, priority->delta, 0); #elif TARGET==WIN32 static HANDLE ph=0, th=0; static DWORD w32_classes[4]={IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS}; if(!ph) ph=GetCurrentProcess(); if(!th) th=GetCurrentThread(); if(priority->class<=4) SetPriorityClass(ph, w32_classes[priority->class-1]); SetThreadPriority(th, priority->delta); #else #if defined(HAVE_SETPRIORITY) setpriority(PRIO_PROCESS, 0, 21-priority->class); #else #error Priority functions missing #endif #endif}#endif/* * This section is specific to Windows 95 LFN API. *//* Just a customized interrupt call procedure */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int call_dos_int(unsigned int funcnum, union REGS *regs, struct SREGS *sregs){ regs->x.ax=funcnum; #ifdef ASM8086 asm{ pushf pop ax or ax, 1 push ax popf }; #else /* Provoke the carry flag */ regs->x.cflag=(regs->x.ax&0x7FFF)+0x8000; #endif intdosx(regs, regs, sregs); _doserrno=(regs->x.cflag!=0)?(regs->x.ax):0; return(regs->x.cflag);}#endif/* Test the specified volume for long filename support */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_test_for_lfn(char *drive){ union REGS regs; struct SREGS sregs; char filesystem[40]; /* Ralf Brown says 32 */ char FAR *fsptr, FAR *dptr; fsptr=(char FAR *)filesystem; dptr=(char FAR *)drive; memset(&sregs, 0, sizeof(sregs)); sregs.es=FP_SEG(fsptr); regs.x.di=FP_OFF(fsptr); regs.x.cx=sizeof(filesystem); sregs.ds=FP_SEG(dptr); regs.x.dx=FP_OFF(dptr); return(call_dos_int(W95_GET_VOLUME_INFO, ®s, &sregs)==0&®s.x.bx&0x4000);}#endif/* Return equivalent canonical short filename for a long filename */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_get_shortname(char *longname, char *shortname, int cb_shortname){ union REGS regs; struct SREGS sregs; char FAR *lnptr, FAR *snptr; memset(&sregs, 0, sizeof(sregs)); if(cb_shortname>=CCHMAXPATH_DOS) { lnptr=(char FAR *)longname; snptr=(char FAR *)shortname; shortname[0]='\0'; sregs.ds=FP_SEG(lnptr); regs.x.si=FP_OFF(lnptr); sregs.es=FP_SEG(snptr); regs.x.di=FP_OFF(snptr); regs.x.cx=W95_GET_SHORTNAME; /* No SUBST expansion, subfunc #1 */ if(!call_dos_int(W95_TRUENAME, ®s, &sregs)) return(strlen(shortname)); else return(0); } else return(0);}#endif/* Changes directory under Windows 95 */#if defined(REARJ)&&TARGET==DOSstatic int w95_chdir(char *longname){ union REGS regs; struct SREGS sregs; char FAR *lnptr; memset(&sregs, 0, sizeof(sregs)); lnptr=(char FAR *)longname; sregs.ds=FP_SEG(lnptr); regs.x.dx=FP_OFF(lnptr); return(call_dos_int(W95_CHDIR, ®s, &sregs)?-1:0);}#endif/* Return equivalent canonical long filename for a short filename */#if (SFX_LEVEL>=ARJ)&&TARGET==DOSstatic int w95_get_longname(char *shortname, char *longname, int cb_longname){ union REGS regs; struct SREGS sregs; char FAR *lnptr, FAR *snptr; memset(&sregs, 0, sizeof(sregs)); if(cb_longname>=CCHMAXPATH_W95) { longname[0]='\0'; lnptr=(char FAR *)longname; snptr=(char FAR *)shortname; sregs.ds=FP_SEG(snptr); regs.x.si=FP_OFF(snptr); sregs.es=FP_SEG(lnptr); regs.x.di=FP_OFF(lnptr); regs.x.cx=W95_GET_LONGNAME; /* No SUBST expansion, subfunc #2 */ if(!call_dos_int(W95_TRUENAME, ®s, &sregs)) return(strlen(longname)); else return(0); } else return(0);}#endif/* Returns 1 if the current OS is Windows NT, 0 if Windows 95 */#if SFX_LEVEL>=ARJ&&TARGET==DOSint test_for_winnt(){ return(0); /* Implemented in ARJ32 */}#endif/* Returns the name of current directory */#if defined(REARJ)&&TARGET==DOSstatic char *w95_cwd(char *dest){ union REGS regs; struct SREGS sregs; char FAR *dptr; dptr=(char FAR *)dest; memset(&sregs, 0, sizeof(sregs)); dest[0]=getdisk()+'A'; dest[1]=':'; dest[2]=PATHSEP_DEFAULT; regs.h.dl=0; sregs.ds=FP_SEG(dptr); regs.x.si=FP_OFF(dptr)+3; return(call_dos_int(W95_CWD, ®s, &sregs)?NULL:dest);}#endif/* Create a directory with longname. Return -1 if failed. */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_mkdir(char *longname){ union REGS regs; struct SREGS sregs; char FAR *lnptr; lnptr=(char FAR *)longname; memset(&sregs, 0, sizeof(sregs)); /* BUG?! No register cleanup in ARJ */ sregs.ds=FP_SEG(lnptr); regs.x.dx=FP_OFF(lnptr); return(call_dos_int(W95_MKDIR, ®s, &sregs)?-1:0);}#endif/* Remove a directory with longname. Return -1 if failed. */#if (SFX_LEVEL>=ARJ||defined(REARJ))&&TARGET==DOSstatic int w95_rmdir(char *longname){ union REGS regs; struct SREGS sregs; char FAR *lnptr; lnptr=(char FAR *)longname; memset(&sregs, 0, sizeof(sregs)); sregs.ds=FP_SEG(lnptr); regs.x.dx=FP_OFF(lnptr); return(call_dos_int(W95_RMDIR, ®s, &sregs)?-1:0);}#endif/* Delete a file */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_unlink(char *longname){ union REGS regs; struct SREGS sregs; char FAR *lnptr; lnptr=(char FAR *)longname; memset(&sregs, 0, sizeof(sregs)); sregs.ds=FP_SEG(lnptr); regs.x.dx=FP_OFF(lnptr); #ifndef REARJ regs.x.cx=FATTR_ARCH|FATTR_SYSTEM|FATTR_RDONLY; #else regs.x.cx=0; #endif regs.x.si=W95_WILDCARDS_DISABLED; /* Forbid wildcard usage */ return(call_dos_int(W95_UNLINK, ®s, &sregs)?-1:0);}#endif/* Rename a file */#if (SFX_LEVEL>=ARJ||defined(REARJ))&&TARGET==DOSstatic int w95_rename(char *longname1, char *longname2){ union REGS regs; struct SREGS sregs; char FAR *lnptr1, FAR *lnptr2; lnptr1=(char FAR *)longname1; lnptr2=(char FAR *)longname2; memset(&sregs, 0, sizeof(sregs)); sregs.ds=FP_SEG(lnptr1); regs.x.dx=FP_OFF(lnptr1); sregs.es=FP_SEG(lnptr2); regs.x.di=FP_OFF(lnptr2); return(call_dos_int(W95_RENAME, ®s, &sregs)?-1:0);}#endif/* Query or change attributes */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_chmod(char *longname, int action, int pmode){ union REGS regs; struct SREGS sregs; char FAR *lnptr; lnptr=(char FAR *)longname; memset(&sregs, 0, sizeof(sregs)); regs.x.bx=action; regs.x.cx=pmode; sregs.ds=FP_SEG(lnptr); regs.x.dx=FP_OFF(lnptr); return(call_dos_int(W95_CHMOD, ®s, &sregs)?-1:regs.x.cx);}#endif/* access() function for LFNs - test if the file has the given access mode */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_access(char *longname, int mode){ if((w95_chmod(longname, W95_GETATTR, 0))==-1) return(-1); else { if((!(mode&2))||!(mode&FATTR_RDONLY)) return(0); else { errno=EACCES; return(-1); } }}#endif/* findfirst() function as implemented in Borland Turbo C++ */#if (SFX_LEVEL>=ARJSFXV||defined(REARJ))&&TARGET==DOSstatic int w95_findfirst(char *path, struct new_ffblk *new_ffblk, int attrib){ union REGS regs; struct SREGS sregs; struct W95_FFBLK w95_ffblk, FAR *fb_ptr; char FAR *p_ptr; memset(&sregs, 0, sizeof(sregs)); fb_ptr=(struct W95_FFBLK FAR *)&w95_ffblk; p_ptr=(char FAR *)path; sregs.ds=FP_SEG(p_ptr); regs.x.dx=FP_OFF(p_ptr); sregs.es=FP_SEG(fb_ptr); regs.x.di=FP_OFF(fb_ptr); regs.x.cx=attrib; regs.x.si=W95_DT_DOS; /* Use DOS date/time format */ if(!call_dos_int(W95_FINDFIRST, ®s, &sregs)) { #if SFX_LEVEL>=ARJ||defined(REARJ) new_ffblk->ff_handle=regs.x.ax; /* Preserve handle for findclose */ strcpy(new_ffblk->ff_name, w95_ffblk.ff_longname); new_ffblk->ff_atime=w95_ffblk.ff_atime; new_ffblk->ff_ctime=w95_ffblk.ff_ctime; #endif new_ffblk->ff_attrib=(char)w95_ffblk.ff_attrib; new_ffblk->ff_ftime=w95_ffblk.ff_ftime; new_ffblk->ff_fsize=w95_ffblk.ff_fsize; #if SFX_LEVEL==ARJSFXV memset(&sregs, 0, sizeof(sregs)); regs.x.bx=regs.x.ax; /* Transfer FF handle */ call_dos_int(W95_FINDCLOSE, ®s, &sregs); #endif return(0); } else return(-1);}#endif/* findnext() function as implemented in Borland Turbo C++ */#if (SFX_LEVEL>=ARJ||defined(REARJ))&&TARGET==DOSstatic int w95_findnext(struct new_ffblk *new_ffblk){ union REGS regs; struct SREGS sregs; struct W95_FFBLK w95_ffblk, FAR *fb_ptr; memset(&sregs, 0, sizeof(sregs)); fb_ptr=(struct W95_FFBLK FAR *)&w95_ffblk; sregs.es=FP_SEG(fb_ptr); regs.x.di=FP_OFF(fb_ptr); regs.x.bx=new_ffblk->ff_handle; regs.x.si=W95_DT_DOS; /* Not present in original ARJ! */ if(!call_dos_int(W95_FINDNEXT, ®s, &sregs)) { new_ffblk->ff_attrib=(char)w95_ffblk.ff_attrib; strcpy(new_ffblk->ff_name, w95_ffblk.ff_longname); new_ffblk->ff_ftime=w95_ffblk.ff_ftime; new_ffblk->ff_atime=w95_ffblk.ff_atime; new_ffblk->ff_ctime=w95_ffblk.ff_ctime; new_ffblk->ff_fsize=w95_ffblk.ff_fsize; return(0); } else return(-1);}#endif/* Close search (specific to Windows 95) */#if (SFX_LEVEL>=ARJSFXV||defined(REARJ))&&TARGET==DOSstatic void w95_findclose(struct new_ffblk *new_ffblk){ union REGS regs; struct SREGS sregs; memset(&sregs, 0, sizeof(sregs)); regs.x.bx=new_ffblk->ff_handle; call_dos_int(W95_FINDCLOSE, ®s, &sregs);}#endif/* Create a file with the same options as given for _open, return handle */#if (SFX_LEVEL>=ARJSFX||defined(REARJ))&&TARGET==DOSstatic int w95_creat(char *longname, int access){ union REGS regs; struct SREGS sregs; char FAR *lnptr; lnptr=(char FAR *)longname; memset(&sregs, 0, sizeof(sregs)); sregs.ds=FP_SEG(lnptr); regs.x.si=FP_OFF(lnptr); regs.x.bx=access&(O_RDONLY|O_WRONLY); regs.x.cx=32; regs.x.dx=0; regs.x.di=1; /* Translate FCNTL actions into Win95 actions */ if(access&O_CREAT) regs.x.dx|=W95_A_CREAT; if(access&O_TRUNC) regs.x.dx|=W95_A_TRUNC; if(access&O_EXCL) regs.x.dx|=W95_A_EXCL; return(call_dos_int(W95_OPEN, ®s, &sregs)?-1:regs.x.ax);}#endif/* Stamp date/time of last access on handle. Note that Win95 does not support time of last access. */#if (SFX_LEVEL>=ARJSFXV)&&TARGET==DOSstatic int w95_set_dta(int handle, unsigned long ftime){ union REGS regs; struct SREGS sregs; memset(&sregs, 0, sizeof(sregs)); regs.x.bx=handle; regs.x.cx=0; regs.x.dx=(unsigned short)ftime>>16; return(call_dos_int(W95_SET_DTA, ®s, &sregs)?-1:0);}#endif/* Stamp date/time of last access on handle. Note that Win95 does not support time of last access. */#if (SFX_LEVEL>=ARJSFXV)&&TARGET==DOSstatic int w95_set_dtc(int handle, unsigned long ftime){ union REGS regs; struct SREGS sregs; memset(&sregs, 0, sizeof(sregs)); regs.x.bx=handle; regs.x.cx=(unsigned short)(ftime%65536L); regs.x.dx=(unsigned short)ftime>>16; regs.x.si=0; /* Number of 1/100ths */ return(call_dos_int(W95_SET_DTC, ®s, &sregs)?-1:0);}#endif/* * Now, some less OS-dependent routines. *//* Return pointer to first character following a drivespec/relative pathspec so names like "\VIRUS.COM" will be transformed to safe "VIRUS.COM" */#if SFX_LEVEL>=ARJSFX#if SFX_LEVEL>=ARJSFXVstatic char *validate_path(char *name, int action)#elsestatic char *validate_path(char *name)#endif{#if SFX_LEVEL>=ARJSFXV if(action!=VALIDATE_NOTHING) {#endif#ifdef HAVE_DRIVES if(name[0]!='\0'&&name[1]==':') name+=2; /* Skip over drivespecs */#endif#if SFX_LEVEL>=ARJSFXV if(action!=VALIDATE_DRIVESPEC) {#endif if(name[0]=='.') { if(name[1]=='.'&&(name[2]==PATHSEP_DEFAULT||name[2]==PATHSEP_UNIX)) name++; /* "..\" relative path */ if(name[1]==PATHSEP_DEFAULT||name[1]==PATHSEP_UNIX) name++; /* ".\" relative path */ } if(name[0]==PATHSEP_DEFAULT||name[0]==PATHSEP_UNIX) name++; /* "\" - revert to root */#if SFX_LEVEL>=ARJSFXV } }#endif return(name);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -