📄 ckufio.c
字号:
if (n < 0 || n >= ZNFILS) return(-1); else return( (fp[n] == NULL) ? 0 : 1 );#endif /* COMMENT */}/* Z C H K I -- Check if input file exists and is readable *//* Returns: >= 0 if the file can be read (returns the size). -1 if file doesn't exist or can't be accessed, -2 if file exists but is not readable (e.g. a directory file). -3 if file exists but protected against read access.*//* For Berkeley Unix, a file must be of type "regular" to be readable. Directory files, special files, and symbolic links are not readable.*/longzchki(name) char *name; { struct stat buf; int x;#ifdef UNIX x = strlen(name); if (x == 9 && !strcmp(name,"/dev/null")) return(0);#endif /* UNIX */ x = stat(name,&buf); if (x < 0) { debug(F111,"zchki stat fails",name,errno); return(-1); } if (!S_ISREG (buf.st_mode)) { /* Must be regular file */ debug(F111,"zchki skipping:",name,x); return(-2); } debug(F111,"zchki stat ok:",name,x);#ifdef OXOS priv_on();#endif /* OXOS */ x = access(name,R_OK);#ifdef OXOS priv_chk();#endif /* OXOS */ if (x < 0) { /* Is the file accessible? */ debug(F111," access failed:",name,x); /* No */ return(-3); } else { iflen = buf.st_size; /* Yes, remember size */ strncpy(nambuf,name,MAXNAMLEN); /* and name globally. */ debug(F111," access ok:",name,(int) iflen); return( (iflen > -1L) ? iflen : 0L ); }}/* Z C H K O -- Check if output file can be created *//* Returns -1 if write permission for the file would be denied, 0 otherwise.*/intzchko(name) char *name; { int i, x; char *s; if (!name) return(-1); /* Watch out for null pointer. */ x = (int)strlen(name); /* Get length of filename */ debug(F101," length","",x);#ifdef UNIX/* Writing to null device is OK.*/ if (x == 9 && !strcmp(name,"/dev/null")) return(0);#endif /* UNIX */ s = malloc(x+3); /* Must copy because we can't */ if (!s) { /* write into our argument. */ fprintf(stderr,"Malloc error 46\n"); return(-1); } strcpy(s,name); for (i = x; i > 0; i--) /* Strip filename from right. */ if (ISDIRSEP(s[i-1])) break; debug(F101," i","",i);#ifdef COMMENT/* X/OPEN XPG3-compliant systems fail if argument ends with "/"... */ if (i == 0) /* If no path, use current directory */ strcpy(s,"./"); else /* Otherwise, use given one. */ s[i] = '\0';#else/* So now we use "path/." if path given, or "." if no path given. */ s[i++] = '.'; /* Append "." to path. */ s[i] = '\0';#endif /* COMMENT */#ifdef OXOS priv_on();#endif /* OXOS */#ifdef OS2 /* No unwritable directories in OS/2 */ x = 0;#else x = access(s,W_OK); /* Check access of path. */#endif /* OS2 */#ifdef OXOS priv_chk();#endif /* OXOS */ if (x < 0) debug(F111,"zchko access failed:",s,errno); else debug(F111,"zchko access ok:",s,x); free(s); /* Free temporary storage */ return((x < 0) ? -1 : 0); /* and return. */}/* Z D E L E T -- Delete the named file. */intzdelet(name) char *name; { return(unlink(name));}/* Z R T O L -- Convert remote filename into local form *//* For UNIX, this means changing uppercase letters to lowercase. */VOIDzrtol(name,name2) char *name, *name2; { char *p; int flag = 0; debug(F101,"zrtol name","",name); debug(F101,"zrtol name2","",name2); if (!name || !name2) return; debug(F101,"zrtol input","",name); p = name2; for ( ; *name != '\0'; name++) { if (*name > ' ') flag = 1; /* Strip leading blanks and controls */ if (flag == 0 && *name < '!') continue; *p++ = isupper(*name) ? tolower(*name) : *name; } *p-- = '\0'; /* Terminate */ while (*p < '!' && p > name2) /* Strip trailing blanks & contronls */ *p-- = '\0';#ifdef OS2 if (!IsFileNameValid(name2)) ChangeNameForFAT(name2);#endif /* OS2 */ debug(F110,"zrtol result",name2,0);}/* Z S T R I P -- Strip device & directory name from file specification *//* Strip pathname from filename "name", return pointer to result in name2 */#ifdef pdp11static char work[100]; /* buffer for use by zstrip and zltor */#elsestatic char work[257];#endif /* pdp11 */VOIDzstrip(name,name2) char *name, **name2; { char *cp, *pp; debug(F110,"zstrip before",name,0); pp = work;#ifdef DTILDE if (*name == '~') name++;#endif /* DTILDE */ for (cp = name; *cp != '\0'; cp++) { if (ISDIRSEP(*cp)) pp = work; else *pp++ = *cp; } *pp = '\0'; /* Terminate the string */ *name2 = work; debug(F110,"zstrip after",*name2,0);}/* Z L T O R -- Local TO Remote */VOIDzltor(name,name2) char *name, *name2; { char *cp, *pp; int dc = 0;#ifdef aegis char *namechars; int tilde = 0, bslash = 0; if ((namechars = getenv("NAMECHARS")) != NULL) { if (xindex(namechars, '~' ) != NULL) tilde = '~'; if (xindex(namechars, '\\') != NULL) bslash = '\\'; } else { tilde = '~'; bslash = '\\'; }#endif /* aegis */ debug(F110,"zltor",name,0); pp = work;#ifdef aegis cp = name; if (tilde && *cp == tilde) ++cp; for (; *cp != '\0'; cp++) { if (*cp == '/' || *cp == bslash) { /* strip path name */#else for (cp = name; *cp != '\0'; cp++) { /* strip path name */ if (ISDIRSEP(*cp)) {#endif /* aegis */ dc = 0; pp = work; } else if (islower(*cp)) *pp++ = toupper(*cp); /* Uppercase letters */ else if (*cp == '~') *pp++ = 'X'; /* Change tilde to 'X' */ else if (*cp == '#') *pp++ = 'X'; /* Change number sign to 'X' */ else if ((*cp == '.') && (++dc > 1)) *pp++ = 'X'; /* & extra dots */ else *pp++ = *cp; } *pp = '\0'; /* Tie it off. */ cp = name2; /* If nothing before dot, */ if (*work == '.') *cp++ = 'X'; /* insert 'X' */ strcpy(cp,work); debug(F110," name2",name2,0);}/* Z C H D I R -- Change directory *//* Call with: dirnam = pointer to name of directory to change to, which may be "" or NULL to indicate user's home directory. Returns: 0 on failure 1 on success*/intzchdir(dirnam) char *dirnam; { char *hd, *sp, *p; debug(F110,"zchdir",dirnam,0); if (dirnam == NULL || dirnam == "" || *dirnam == '\0') /* If arg is null */ dirnam = zhome(); /* use user's home directory. */ sp = dirnam; debug(F110,"zchdir 2",dirnam,0);#ifdef DTILDE hd = tilde_expand(dirnam); /* Attempt to expand tilde */ if (*hd == '\0') hd = dirnam; /* in directory name. */#else hd = dirnam;#endif /* DTILDE */ debug(F110,"zchdir 3",hd,0);#ifdef pdp11 /* Just to save some space */ return((chdir(hd) == 0) ? 1 : 0);#else#ifdef OS2 if (isalpha(hd[0]) && hd[1] == ':') { if (zchdsk(hd[0])) return(0); if (hd[2] == 0) return(1); /* Handle drive-only case */ }#endif /* OS2 */ if (chdir(hd) == 0) return(1); /* Try to cd */ /* (===OS2===) */ p = sp; /* Failed, lowercase it. */ while (*p) { if (isupper(*p)) *p = tolower(*p); p++; } debug(F110,"zchdir 4",hd,0);#ifdef DTILDE hd = tilde_expand(sp); /* Try again to expand tilde */ if (*hd == '\0') hd = sp;#else hd = sp; /* Point to result */#endif /* DTILDE */ debug(F110,"zchdir 5",hd,0); return((chdir(hd) == 0) ? 1 : 0);#endif /* pdp11 */}/* Z H O M E -- Return pointer to user's home directory */char *zhome() { char *home = getenv("HOME");#ifdef OS2 extern char startupdir[]; return(home ? home : startupdir);#else return(home ? home : ".");#endif}/* Z G T D I R -- Return pointer to user's current directory */#ifdef pdp11#define CWDBL 80 /* Save every byte we can... */#else#ifdef MAXPATHLEN#define CWDBL MAXPATHLEN#else#define CWDBL 100#endif /* MAXPATHLEN */#endif /* pdp11 */static char cwdbuf[CWDBL+1];char *zgtdir() { char *buf;#ifdef BSD44 extern char *getwd(); buf = cwdbuf; return(getwd(buf));#else#ifdef SVORPOSIX extern char *getcwd(); buf = cwdbuf; return(getcwd(buf,CWDBL));#else#ifdef OS2 extern char *getcwd(); buf = cwdbuf; return(getcwd(buf,CWDBL));#else#ifdef BSD4 extern char *getwd(); buf = cwdbuf; return(getwd(buf));#else return("directory unknown");#endif /* BSD4 */#endif /* OS2 */#endif /* SYSVORPOSIX */#endif /* BSD44 */}/* Z X C M D -- Run a system command so its output can be read like a file */intzxcmd(filnum,comand) int filnum; char *comand; {#ifdef OS2 if (chkfn(filnum) < 0) return(-1); /* Need a valid Kermit file number. */ if (filnum == ZSTDIO || filnum == ZCTERM) /* But not one of these. */ return(0); if (filnum == ZIFILE || filnum == ZRFILE) { /* Input from a command */ if (priv_chk() || ((fp[filnum] = popen(comand,"r")) == NULL)) return(0); } else { /* Output to a command */ if (priv_chk() || ((fp[filnum] = popen(comand,"w")) == NULL)) return(0); } ispipe[filnum] = 1; return(1);#else /* Not OS2 */ int pipes[2]; int out; if (chkfn(filnum) < 0) return(-1); /* Need a valid Kermit file number. */ if (filnum == ZSTDIO || filnum == ZCTERM) /* But not one of these. */ return(0); out = (filnum == ZIFILE || filnum == ZRFILE) ? 0 : 1 ;/* Output to a command */ if (out) { /* Need popen() to do this. */#ifdef NOPOPEN return(0); /* no popen(), fail. */#else/* Use popen() to run the command. */#ifdef _POSIX_SOURCE/* Strictly speaking, popen() is not available in POSIX.1 */#define DCLPOPEN#endif /* _POSIX_SOURCE */#ifdef DCLPOPEN/* popen() needs declaring because it's not declared in <stdio.h> */ FILE *popen();#endif /* DCLPOPEN */ if (priv_chk() || ((fp[filnum] = popen(comand,"w")) == NULL)) return(0); else return(1);#endif /* NOPOPEN */ }/* Input from a command */ if (pipe(pipes) != 0) { debug(F100,"zxcmd pipe failure","",0); return(0); /* can't make pipe, fail */ }/* Create a fork in which to run the named process */#ifdef aegis if ((pid = vfork()) == 0) { /* child */#else if ((pid = fork()) == 0) { /* child */#endif/* We're in the fork. */ char *shpath, *shname, *shptr; /* Find user's preferred shell */#ifndef aegis struct passwd *p; char *defshell = "/bin/sh"; /* default shell */#endif /* aegis */ if (priv_can()) exit(1); /* Turn off any privileges! */ debug(F101,"zxcmd pid","",pid); close(pipes[0]); /* close input side of pipe */ close(0); /* close stdin */ if (open("/dev/null",0) < 0) return(0); /* replace input by null */#ifndef SVORPOSIX dup2(pipes[1],1); /* BSD: replace stdout & stderr */ dup2(pipes[1],2); /* by the pipe */#else close(1); /* AT&T: close stdout */ if ( dup(pipes[1]) != 1 ) /* Send stdout to the pipe */ return(0); close(2); /* Send stderr to the pipe */ if ( dup(pipes[1]) != 2 ) return(0);#endif /* SVORPOSIX */ close(pipes[1]); /* Don't need this any more. */#ifdef aegis if ((shpath = getenv("SERVERSHELL")) == NULL) shpath = "/bin/sh";#else shpath = getenv("SHELL"); /* What shell? */ if (shpath == NULL) { p = getpwuid( real_uid() ); /* Get login data */ if (p == (struct passwd *)NULL || !*(p->pw_shell)) shpath = defshell; else shpath = p->pw_shell; }#endif /* aegis */ shptr = shname = shpath; while (*shptr != '\0') if (*shptr++ == '/') shname = shptr; debug(F100,"zxcmd...","",0); debug(F110,shpath,shname,0); execl(shpath,shname,"-c",comand,(char *)NULL); /* Execute the cmd */ exit(0); /* just punt if it failed. */ } else if (pid == (PID_T) -1) { debug(F100,"zxcmd fork failure","",0); return(0); } debug(F101,"zxcmd pid","",pid); if (out) { close(pipes[0]); /* Don't need the input side */ fp[filnum] = fdopen(pipes[1],"w"); /* Open a stream for output. */ fp[ZSYSFN] = fp[filnum]; /* Remember. */ zoutcnt = 0; /* (PWP) reset input buffer */ zoutptr = zoutbuffer; } else { close(pipes[1]); /* Don't need the output side */ fp[filnum] = fdopen(pipes[0],"r"); /* Open a stream for input. */ fp[ZSYSFN] = fp[filnum]; /* Remember. */ zincnt = 0; /* (PWP) reset input buffer */ zinptr = zinbuffer; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -