📄 environ.c
字号:
ptr[0]-=('a'-'A'); /* Convert to upper case */ ptr++; length--; } } #elif TARGET==OS2 COUNTRYCODE cc; cc.country=cc.codepage=0; DosCaseMap(length, &cc, ptr); #else unsigned char x; /* ASR fix 10/04/2002: this fixes a GCC v 3.0 optimization bug */ while(length-->0) { x=*ptr; *ptr++=toupper(x); } #endif}#endif/* Sums two unixtime values (for systems with different implementation of time_t and for Year 2106 compliance) */#if SFX_LEVEL>=ARJtime_t sum_time(time_t t1, time_t t2){ return(t1+t2);}#endif/* Subtracts two unixtime values (for systems with different implementation of time_t and for Year 2106 compliance) */#ifdef REARJtime_t sub_time(time_t t1, time_t t2){ return(t1-t2);}#endif/* Depending of LFN support, converts the path specification to UPPERCASE */#if SFX_LEVEL>=ARJSFX||defined(REARJ)void case_path(char *s){ #if TARGET==DOS if(lfn_supported==LFN_NOT_SUPPORTED) strupper(s); #else /* Case-preserving or case-sensitive systems have nothing to do here */ #endif}#endif/* Looks for duplicate drive specifications in the arguments, returns 1 if found one, or 0 if none were found. */#if SFX_LEVEL>=ARJ&&TARGET!=UNIXint find_dupl_drivespecs(char **argtable, int args){ int cur_arg, cx_arg; if(args<=1) { if(listchars_allowed==0||argtable[0][0]!=listchar) return(0); else return(1); } else { for(cur_arg=0; cur_arg<args; cur_arg++) { if(argtable[cur_arg][1]!=':'&&strcmp(argtable[cur_arg], nonexist_name)) return(1); } for(cur_arg=0; cur_arg<args; cur_arg++) for(cx_arg=0; cx_arg<args; cx_arg++) { if(cx_arg!=cur_arg) { if(argtable[cx_arg][0]==argtable[cur_arg][0]) return(1); } } return(0); }}#endif/* Returns 0 if monopolized R/O access to the file can be granted, -1 if not */#if SFX_LEVEL>=ARJSFXVint file_test_access(char *name){ #if TARGET==DOS char tmp_name[CCHMAXPATH]; #endif int handle; #if TARGET==DOS if(_osmajor>=3&&!disable_sharing) { strcpy(tmp_name, name); if(lfn_supported!=LFN_NOT_SUPPORTED) w95_get_shortname(name, tmp_name, sizeof(tmp_name)); #if COMPILER==BCC if((handle=_open(tmp_name, O_BINARY|O_DENYALL|O_RDONLY))==-1) return(-1); #elif COMPILER==MSC if((handle=sopen(tmp_name, O_BINARY|O_RDONLY, SH_DENYRW))==-1) return(-1); #endif close(handle); } return(0); #elif TARGET==OS2||TARGET==WIN32 if((handle=sopen(name, O_BINARY|O_RDONLY, SH_DENYRW))==-1) return(-1); close(handle); return(0); #elif TARGET==UNIX struct flock flk; int rc; if((handle=open(name, O_RDONLY))==-1) return(-1); memset(&flk, 0, sizeof(flk)); rc=fcntl(handle, F_GETLK, &flk); close(handle); return(((rc==-1&&errno!=EINVAL)||(rc!=1&&flk.l_type==F_RDLCK))?-1:0); #endif}#endif/* Detect long filename support */#if SFX_LEVEL>=ARJSFX||defined(REARJ)int detect_lfns(){ #if TARGET==DOS if(_osmajor<7) return(lfn_supported=0); else return(lfn_supported=w95_test_for_lfn(drive_c)); #else return(lfn_supported=1); /* Setting to 0 will disable DTA/DTC handling! */ #endif}#endif/* Detect extended attribute support */#if SFX_LEVEL>=ARJSFXVint detect_eas(){ #if TARGET==OS2 ea_supported=1; #elif TARGET==WIN32 OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize=sizeof(osvi); GetVersionEx(&osvi); return(ea_supported=(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)); #else ea_supported=0; #endif return(ea_supported);}#endif/* Null subroutine for compiler bugs */void nullsub(int arg, ...){}/* Delay */#if SFX_LEVEL>=ARJSFX||defined(REARJ)||defined(REGISTER)||defined(ARJDISP)void arj_delay(unsigned int seconds){ #if TARGET==DOS #if COMPILER==MSC long c_time, e_time, t_time; /* This is inappropriate for some rare machines with non-standard timer arrangement, e.g. Tandy 2000 but at least it doesn't involve reprogramming the timer ports. */ e_time=(long)seconds*182L/10L; while(e_time--) { g_timer(t_time); c_time=t_time; do { g_timer(c_time); } while(c_time==t_time); } #else sleep(seconds); #endif #elif TARGET==OS2 DosSleep(seconds*1000L); #elif TARGET==WIN32 Sleep(seconds*1000L); #else sleep(seconds); #endif}#endif/* Collect memory statistics (for debugging purposes) */#if SFX_LEVEL>=ARJSFXVvoid mem_stats(){ if(debug_enabled&&strchr(debug_opt, 'v')!=NULL) { #if SFX_LEVEL>=ARJ msg_cprintf(0, M_MEMSTATS, coreleft(), verify_heap(), farcoreleft(), verify_far_heap(), get_stack_space()); #else msg_cprintf(0, M_MEMSTATS, coreleft(), farcoreleft()); #endif }}#endif/* Interrupt 24h handler */#if SFX_LEVEL>=ARJSFXV&&TARGET==DOS#if COMPILER==BCCvoid interrupt int24_fatal_handler(unsigned int bp, unsigned int di, unsigned int si, unsigned int ds, unsigned int es, unsigned int dx, unsigned int cx, unsigned int bx, unsigned int ax)#elif COMPILER==MSCvoid _interrupt _far int24_fatal_handler( unsigned int es, unsigned int ds, unsigned int di, unsigned int si, unsigned int bp, unsigned int sp, unsigned int bx, unsigned int dx, unsigned int cx, unsigned int ax, unsigned int ip, unsigned int cs, unsigned int flags)#endif{ ax=INT24_FAIL;}#endif/* Check for the existence of file given; INT 24h handler is reset to ensure that the FAIL action is automatically generated instead of prompting the user for action. */#if SFX_LEVEL>=ARJSFX||defined(REARJ)||defined(REGISTER)int file_exists(char *name){ int rc; #if TARGET==DOS #if COMPILER==BCC void interrupt (*oldhdl)(); #elif COMPILER==MSC void (_interrupt _far *oldhdl)(); #endif #if SFX_LEVEL>=ARJSFXV if(is_dos_31) rc=file_access(name, 0); else { oldhdl=getvect(INT24); setvect(INT24, int24_fatal_handler); rc=file_access(name, 0); setvect(INT24, oldhdl); } #else rc=file_access(name, 0); #endif #elif TARGET==OS2 rc=file_access(name, 0); #else rc=file_access(name, F_OK); #endif return(!rc);}#endif/* An extended fopen that supports long filenames and uses sharing. */#if SFX_LEVEL>=ARJSFX||defined(REARJ)FILE *file_open(char *name, char *mode){ #if TARGET==DOS char tmp_name[CCHMAXPATH]; #endif #if SFX_LEVEL>=ARJSFXV char tmp_mode[10]; #endif #if COMPILER!=BCC&&SFX_LEVEL>=ARJSFXV int shflag; #endif #if SFX_LEVEL>=ARJSFXV||TARGET==DOS int handle; #endif #if SFX_LEVEL>=ARJSFXV int oflag; #endif #if TARGET==DOS strcpy(tmp_name, name); if(lfn_supported!=LFN_NOT_SUPPORTED) { if(strchr(mode, 'a')!=NULL||strchr(mode, 'w')!=NULL) { if(w95_access(name, 0)) { /* If the file does not exist, continue here, otherwise get its short name and process with fopen. */ if((handle=w95_creat(name, O_CREAT|O_TRUNC|O_WRONLY))==-1) return(NULL); else close(handle); /* At this point, the file has been created but has a zero length. Now we can query its short name and use DOS functions to access it. */ } } w95_get_shortname(name, tmp_name, sizeof(tmp_name)); } #endif #if SFX_LEVEL>=ARJSFXV if(disable_sharing) return(fopen(name, mode)); else { strcpyn(tmp_mode, mode, 9); switch(tmp_mode[0]) { case 'r': oflag=0; break; case 'w': oflag=O_CREAT|O_TRUNC; break; case 'a': oflag=O_CREAT|O_APPEND; break; default: return(NULL); } if(tmp_mode[1]=='+'||tmp_mode[1]!='\0'&&tmp_mode[2]=='+') oflag|=O_RDWR; else oflag|=(tmp_mode[0]=='r')?O_RDONLY:O_WRONLY; #if TARGET!=UNIX if(tmp_mode[1]=='b'||tmp_mode[2]=='b') oflag|=O_BINARY; #endif #if TARGET==DOS if(_osmajor>=3) /* Sharing modes for DOS v 3.0+ */ { #if COMPILER==BCC if(tmp_mode[1]=='+'||tmp_mode[1]!='\0'&&tmp_mode[2]=='+') oflag|=O_DENYWRITE; else oflag|=O_DENYNONE; #else shflag=(tmp_mode[1]=='+'||tmp_mode[1]!='\0'&&tmp_mode[2]=='+')?SH_DENYWR:SH_DENYNO; #endif } #if COMPILER==BCC handle=open(tmp_name, oflag, S_IREAD|S_IWRITE); #elif COMPILER==MSC /* Advanced mode - designed for OS/2 */ if((handle=sopen(tmp_name, oflag, shflag, S_IREAD|S_IWRITE))==-1) { if(errno!=EACCES) return(NULL); /* Provoke INT 24h call */ f_file_ptr=name; handle=open(tmp_name, oflag, S_IREAD|S_IWRITE); f_file_ptr=NULL; if(handle==-1) /* User abort */ return(NULL); close(handle); /* Try to reopen the file in shared mode */ if((handle=sopen(tmp_name, oflag, shflag, S_IREAD|S_IWRITE))==-1) if((handle=open(tmp_name, oflag, S_IREAD|S_IWRITE))==-1) return(NULL); } #endif if(handle!=-1) return(fdopen(handle, tmp_mode)); else return(NULL); #elif TARGET==OS2||TARGET==WIN32 { shflag=(mode[1]=='+'||mode[1]!='\0'&&mode[2]=='+')?SH_DENYWR:SH_DENYNO; handle=sopen(name, oflag, shflag, S_IREAD|S_IWRITE); if(handle!=-1) return((FILE *)fdopen(handle, mode)); else return(NULL); } #elif TARGET==UNIX { struct flock flk; /* Disengage any links so we don't follow them */ if(mode[0]=='w') unlink(name); /* Deny write activities if mixed-mode access */ if(mode[1]=='+'||mode[1]!='\0'&&mode[2]=='+') { memset(&flk, 0, sizeof(flk)); flk.l_type=F_WRLCK; /* ASR fix 01/10/2003 -- re-fix to handle umask 022 correctly */ if((handle=open(name, oflag, 0644))==-1) return(NULL); if(fcntl(handle, F_SETLK, &flk)==-1&&errno!=EINVAL) { close(handle); return(NULL); } return(fdopen(handle, mode)); } else return(fopen(name, mode)); } #endif } #else #if TARGET==DOS return(fopen(tmp_name, mode)); #else return(fopen(name, mode)); #endif #endif}#endif/* Convert the given path to uppercase and validate it */#if SFX_LEVEL>=ARJSFXVvoid default_case_path(char *dest, char *src){ case_path(strcpy(dest, validate_path(src, validate_style)));}#endif/* Checks stdin against EOF (for raw input mode) */#if (SFX_LEVEL>=ARJSFXV||defined(ARJDISP))&&TARGET==DOSstatic void check_stdin(){ int rc; union REGS regs; regs.x.ax=0x4400; /* IOCTL - query device */ regs.x.bx=0; /* STDIN */ intdos(®s, ®s); rc=regs.x.dx; #ifndef ARJDISP if(!(rc&CHDI_NUL)) { if(rc&CHDI_SET) return; if(!eof(0)) return; } error(M_CANTREAD); #endif}#endif/* Reads character from console */#if SFX_LEVEL>=ARJSFXV||defined(ARJDISP)int uni_getch(){ #if TARGET==DOS union REGS regs; check_stdin(); regs.h.ah=0x08; /* Read character without echo */ intdos(®s, ®s); return((int)(regs.h.al==0x0D?0x0A:regs.h.al)); #elif TARGET==OS2 KBDKEYINFO keyinfo; KbdCharIn(&keyinfo, IO_WAIT, 0); return(keyinfo.chChar); #elif TARGET==WIN32 return(getch()); #elif defined(SUNOS) static struct termio cookedmode,rawmode; static int cookedok; int key; if (!cookedok) { ioctl(0,TCGETA,&cookedmode); ioctl(0,TCGETA,&rawmode); rawmode.c_iflag=IXON|IXOFF; rawmode.c_oflag&=~OPOST; rawmode.c_lflag=0; rawmode.c_cc[VEOF]=1; cookedok=1; } ioctl(0,TCSETAW,&rawmode); key=getchar(); ioctl(0,TCSETAW,&cookedmode); return key; #else return(getchar()); #endif}#endif/* Returns current system time, in # of ticks since midnight */#if SFX_LEVEL>=ARJSFXV||defined(REGISTER)unsigned long get_ticks(){ struct time sttime; arj_gettime(&sttime); return(((unsigned long)sttime.ti_hour*3600L+(unsigned long)sttime.ti_min*60L+ (unsigned long)sttime.ti_sec)*100L+(unsigned long)sttime.ti_hund);}#endif/* Retrieves current directory */#if SFX_LEVEL>=ARJSFX&&SFX_LEVEL<=ARJSFXVvoid file_getcwd(char *buf, int len){ getcwd(buf, len);}#elif defined(REARJ)char *file_getcwd(char *buf){ #if TARGET==DOS if(lfn_supported!=LFN_NOT_SUPPORTED) return(w95_cwd(buf)); else return(getcwd(buf, CCHMAXPATH_W95)); #else #if COMPILER==ICC return(_getcwd(buf, CCHMAXPATH)); #else return(getcwd(buf, CCHMAXPATH)); #endif #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -