📄 ecurz.c
字号:
--Lleft; return(*cdq++);} /* end of readline *//*+------------------------------------------------------------------------- mkdir(dpath,dmode) Directory-creating routines from Public Domain TAR by John Gilmore Make a directory. Compatible with the mkdir() system call on 4.2BSD.--------------------------------------------------------------------------*/#if defined(M_XENIX)#define TERM_SIGNAL(status) ((status) & 0x7F)#define TERM_COREDUMP(status) (((status) & 0x80) != 0)#define TERM_VALUE(status) ((status) >> 8)mkdir(dpath,dmode)char *dpath;int dmode;{ int cpid,status; struct stat statbuf; if(!stat(dpath,&statbuf)) { errno = EEXIST; /* Stat worked,so it already exists */ return(-1); } /* If stat fails for a reason other than non-existence,return error */ if(errno != ENOENT) return(-1); switch(cpid = fork()) { case -1: /* Error in fork() */ return(-1); /* Errno is set already */ case 0: /* Child process */ /* * Cheap hack to set mode of new directory. Since this * child process is going away anyway,we zap its umask. * FIXME,this won't suffice to set SUID,SGID,etc. on this * directory. Does anybody care? */ status = umask(0); /* Get current umask */ status = umask(status | (0777 & ~dmode)); /* Set for mkdir */ execl("/bin/mkdir","mkdir",dpath,(char *)0); _exit(-1); /* Can't exec /bin/mkdir */ default: /* Parent process */ while(cpid != wait(&status)) ; /* Wait for kid to finish */ } if(TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0) { errno = EIO; /* We don't know why,but */ return(-1); /* /bin/mkdir failed */ } return(0);} /* end of mkdir */#endif /* M_XENIX *//*+------------------------------------------------------------------------- make_dirs(pathname) Directory-creating routines from Public Domain TAR by John Gilmore After a file/link/symlink/dir creation has failed, see if it's because some required directory was not present, and if so, create all required dirs.--------------------------------------------------------------------------*/intmake_dirs(pathname)register char *pathname;{ register char *p; /* Points into path */ int madeone = 0; /* Did we do anything yet? */ int save_errno = errno; /* Remember caller's errno */ if(errno != ENOENT) return(0); /* Not our problem */ for(p = strchr(pathname,'/'); p != NULL; p = strchr(p+1,'/')) { /* Avoid mkdir of empty string,if leading or double '/' */ if(p == pathname || p[-1] == '/') continue; /* Avoid mkdir where last part of path is '.' */ if(p[-1] == '.' && (p == pathname+1 || p[-2] == '/')) continue; *p = 0; /* Truncate the path there */ if( !mkdir(pathname,0777)) /* Try to create it as a dir */ { sprintf(s128,"Made directory %s",pathname); report_str(s128,-1); madeone++; /* Remember if we made one */ *p = '/'; continue; } *p = '/'; if(errno == EEXIST) /* Directory already exists */ continue; /* * Some other error in the mkdir. We return to the caller. */ break; } errno = save_errno; /* Restore caller's errno */ return(madeone); /* Tell them to retry if we made one */} /* end of make_dirs *//*+------------------------------------------------------------------------- uncaps(str) - make string str lower case--------------------------------------------------------------------------*/voiduncaps(str)register char *str;{ register int itmp; while(itmp = *str) { if(isupper(itmp)) *str = tolower(itmp); str++; }} /* end of uncaps *//*+------------------------------------------------------------------------- isanylc(str) - returns 1 if string str has any lower case letters--------------------------------------------------------------------------*/intisanylc(str)register char *str;{ while(*str) { if(islower(*str)) return(1); str++; } return(0);} /* end of isanylc *//*+------------------------------------------------------------------------- procheader(name) - process incoming file information headerreturns with 0 and FILE *fout open to receive file if good headersand all is right with the filesystem, else returns error code--------------------------------------------------------------------------*/intprocheader(name)char *name;{ register char *openmode,*p; char zmanag2; /* set default parameters and overrides */ fout = (FILE *)0; openmode = "w"; rxfilepos = 0L; Thisbinary = (!Rxascii) || Rxbinary; if(Lzmanag) zmanag = Lzmanag; zmanag2 = zmanag & ZMMASK; /* * Process ZMODEM remote file management requests */ if(!Rxbinary && zconv == ZCNL) /* Remote ASCII override */ Thisbinary = 0; if(zconv == ZCBIN) /* Remote Binary override */ Thisbinary = 1; report_xfer_mode(Thisbinary ? "BINARY" : "ASCII"); this_file_errors = 0; Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L; this_file_length = 0L; initial_filepos = 0L; if(strlen(name)) p = name + 1 + strlen(name); else p = name; if(*p) { /* header has attributes */ int sscanf_count = 0; int SerialNumber = 0; int Filesleft = 0; long TotalLeft = 0; sscanf_count = sscanf(p,"%ld%lo%o%d&d&ld", &Bytesleft, /* file size */ &Modtime, /* secs since 1970 */ &Filemode, /* unix st_mode */ &SerialNumber, /* vaxism */ &Filesleft,&TotalLeft); switch(sscanf_count) { case 6: /* TotalLeft */ if(!TotalToReceive) TotalToReceive = TotalLeft; case 5: /* Filesleft */ if(!npats) npats = Filesleft; default: break; } if(Thisbinary && (zconv == ZCRESUM)) { if(!stat(name,&fout_stat)) /* if file accessible ... */ { openmode = "r+"; rxfilepos = fout_stat.st_size - 1024; /* re-get last 1024 */ if(Bytesleft < rxfilepos) rxfilepos = 0; if(rxfilepos < 0) rxfilepos = 0; initial_filepos = rxfilepos; expect_zrpos = 1; /* don't count first ZRPOS as error */ } } else if(zmanag2 == ZMNEW) { if(!stat(name,&fout_stat)) /* if file accessible ... */ { if(Modtime <= fout_stat.st_mtime) /* ... and not older */ { sprintf(s128,"RECEIVE skipped: %s (same or later date)", name); report_str(s128 + 8,-1); skip_count++; report_error_count();#if defined(LOG_SKIP) ecu_log_event(getppid(),s128);#endif return(ERROR); } openmode = "w"; if(!(fout = our_fopen(name,openmode))) return ZFERR; } } else if(zmanag2 == ZMAPND) { if(!stat(name,&fout_stat)) /* if file accessible ... */ initial_filepos = fout_stat.st_size; } else if(!Rxclob && ((zmanag2 != ZMCLOB)) && !access(name,0)) { sprintf(s128,"RECEIVE skipped: %s (already exists)",name); report_str(s128 + 8,-1); skip_count++; report_error_count();#if defined(LOG_SKIP) ecu_log_event(getppid(),s128);#endif return(ERROR); } if(Filemode & UNIXFILE) ++Thisbinary; report_rxpos(0L); report_str("",0); /* get rid of End of File */ if(Bytesleft != DEFBYTL) { long min_100; this_file_length = Bytesleft; min_100 = 2L + ((((Bytesleft - initial_filepos) * 11L)) * 10L) / (Baudrate * 6L); report_file_rcv_started(name,Bytesleft, Modtime,(unsigned short)Filemode); sprintf(s128,"Receive time this file ~= %2lu:%02lu", min_100 / 100,((min_100 % 100) * 60L) / 100L); if(TotalToReceive) { min_100 = 2L + (((TotalToReceive * 11L)) * 10L) / (Baudrate * 6L); if(Baudrate > 4800) { min_100 *= 13; min_100 /= 9; /* yech ... empirical */ } sprintf(&s128[strlen(s128)],", transaction ~= %2lu:%02lu", min_100 / 100,((min_100 % 100) * 60L) / 100L); } report_transaction(s128); sprintf(s128,"Receiving data (%d%% complete)",(int)0); report_str(s128,0); } } else { long now; for(p=name; *p; ++p) /* change / to _ */ { if( *p == '/') *p = '_'; } if( *--p == '.') /* zap trailing period */ *p = 0; time(&now); report_file_rcv_started(name,0,now,0); } if(!Zmodem && MakeLCPathname && !isanylc(name) && !(Filemode&UNIXFILE)) uncaps(name); strcpy(Pathname,name); report_xfer_mode(Thisbinary?"BINARY":"ASCII"); if(!fout) fout = our_fopen(name,openmode); if(!fout) { if(make_dirs(name)) fout = our_fopen(name,openmode); } if(!fout) { if(errno > sys_nerr) sprintf(s128,"%-0.64s: open errno %d",name,errno); else sprintf(s128,"%-0.64s: open error: %s",name,sys_errlist[errno]); ecu_log_event(getppid(),s128); skip_count++; report_error_count(); return(ERROR); } if(fseek(fout,rxfilepos,0)) { fclose(fout); fout = (FILE *)0; if(errno > sys_nerr) sprintf(s128,"%-0.64s: seek errno %d",name,errno); else sprintf(s128,"%-0.64s: seek error: %s",name,sys_errlist[errno]); ecu_log_event(getppid(),s128); skip_count++; report_error_count(); return(ERROR); } this_file_errors = 0; return(OK);} /* end of procheader *//*+------------------------------------------------------------------------- send_cancel(error) - send cancel string--------------------------------------------------------------------------*/voidsend_cancel(error)int error;{ static char canistr[] = { 24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0 }; register char *cptr = canistr; purgeline(); report_str("",0); report_last_txhdr("^X CAN",!!error); while(*cptr) sendline(*cptr++); Lleft=0;} /* end of send_cancel *//*+------------------------------------------------------------------------- send_ZFIN() - send ZFIN frame and wait for "OO" ack--------------------------------------------------------------------------*/voidsend_ZFIN(){ register n; Readnum = 1; stohdr(0L); for(n = 0; n < 4; n++) { purgeline(); zshhdr(ZFIN,Txhdr); switch(readline(100)) { case 'O': readline(1); /* Discard 2nd 'O' */ return; case RCDO: return; case TIMEOUT: default: break; } }} /* end of send_ZFIN *//*+------------------------------------------------------------------------- tryz() Initialize for Zmodem receive attempt, try to activate Zmodem sender Handles ZSINIT frame Return ZFILE if Zmodem filename received,-1 on error, ZCOMPL if transaction finished, else 0--------------------------------------------------------------------------*/inttryz(){ register c; register n; if(Nozmodem) /* Check for "rb" program name */ return(0); for(n=Zmodem?15:5; --n>=0; ) { /* Set buffer length (0) and capability flags */ stohdr(0L);#if defined(CANBREAK) Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO|CANBRK;#else Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;#endif if(Zctlesc) Txhdr[ZF0] |= TESCCTL; zshhdr(tryzhdrtype,Txhdr); if(tryzhdrtype == ZSKIP) /* Don't skip too far */ tryzhdrtype = ZRINIT; /* CAF 8-21-87 */again: switch(zgethdr(Rxhdr,0)) { case ZRQINIT: continue; case ZEOF: continue; case TIMEOUT: continue; case ZFILE: zconv = Rxhdr[ZF0]; zmanag = Rxhdr[ZF1]; ztrans = Rxhdr[ZF2]; strcpy(s128,"Transfer type: "); if(zconv == ZCRESUM) strcat(s128,"resume interrupted transfer"); else { switch(c = zmanag & ZMMASK) { case 0: strcat(s128,"if destination nonexistent"); break; case ZMAPND: strcat(s128,"append to destination"); break; case ZMCLOB: strcat(s128,"unconditional (overwrite)"); break; case ZMNEW: strcat(s128,"if source newer"); break; default: strcat(s128,"management option "); switch(c) { case ZMNEWL: strcat(s128,"ZMNEWL"); break; case ZMCRC: strcat(s128,"ZMCRC"); break; case ZMDIFF: strcat(s128,"ZMDIFF"); break; case ZMPROT: strcat(s128,"ZMPROT"); break; default: sprintf(s128 + strlen(s128),"%u",c); break; } break; } } report_str(s128,2); tryzhdrtype = ZRINIT; c = zrdata(secbuf,1024); mode(3); if(c == GOTCRCW) return(ZFILE); zshhdr(ZNAK,Txhdr); goto again; case ZSINIT: Zctlesc = TESCCTL & Rxhdr[ZF0]; if(zrdata(Attn,ZATTNLEN) == GOTCRCW) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -