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

📄 ckufio.c

📁 KERMIT工具 这在办公室下载不了,很多人都没有载不到.
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif /* ZDEBUG */#ifdef IKSD    if (inserver && !local && fp[ZIFILE] == stdin) {        int a, i;        a = ttchk();        if (a < 0) return(-2);        for (i = 0; i < a && i < INBUFSIZE; i++) {            zinbuffer[i] = coninc(0);        }        zincnt = i;        /* set pointer to beginning, (== &zinbuffer[0]) */        zinptr = zinbuffer;        if (zincnt == 0) return(-1);        zincnt--;                       /* One less char in buffer */        return((int)(*zinptr++) & 0377); /* because we return the first */    }#endif /* IKSD */    debug(F101,"zinfill kactive","",kactive);    if (!(kactive && ispipe[ZIFILE])) {        if (feof(fp[ZIFILE])) {            debug(F100,"ZINFILL feof","",0);#ifdef ZDEBUG            printf("ZINFILL EOF\n");#endif /* ZDEBUG */            return(-1);        }    }    clearerr(fp[ZIFILE]);#ifdef SELECT    /* Here we can call select() to get a timeout... */    if (kactive && ispipe[ZIFILE]) {        int secs, z = 0;#ifndef NOXFER        if (srvping) {            secs = 1;            debug(F101,"zinfill calling ttwait","",secs);            z = ttwait(fileno(fp[ZIFILE]),secs);            debug(F101,"zinfill ttwait","",z);        }#endif /* NOXFER */        if (z == 0)          return(-3);    }#endif /* SELECT */#ifdef DEBUG    if (deblog) {        int i;        debug(F101,"ZINFILL INBUFSIZE","",INBUFSIZE);#ifdef USE_MEMCPY        memset(zinbuffer, 0xFF, INBUFSIZE);#else        for (i = 0; i < INBUFSIZE; i++) {            zinbuffer[i] = 0xFF;#ifdef COMMENT				/* Too much! */            debug(F101,"ZINFILL zinbuffer[i]","",i);#endif /* COMMENT */        }#endif /* USE_MEMCPY */	ckstrncpy(zinbuffer,"zinbuffer is a valid buffer",INBUFSIZE);	debug(F111,"ZINFILL about to call fread",zinbuffer,zinbuffer);    }#endif /* DEBUG *//*  Note: The following read MUST be nonblocking when reading from a pipe  and we want timeouts to work.  See zxcmd().*/    zincnt = fread(zinbuffer, sizeof (char), INBUFSIZE, fp[ZIFILE]);    debug(F101,"ZINFILL fread","",zincnt); /* Just the size */#ifdef ZDEBUG    printf("FREAD=%d\n",zincnt);#endif /* ZDEBUG */#ifdef CK_CTRLZ    /* If SET FILE EOF CTRL-Z, first Ctrl-Z marks EOF */    if (zincnt > 0 && !binary && eofmethod == XYEOF_Z) {	register int i;	for (i = 0; i < zincnt; i++) {	    if (zinbuffer[i] == SUB) {		zincnt = i;		/* Stop at first Ctrl-Z */		if (i == 0)		  return(-1);		break;	    }        }    }#endif /* CK_CTRLZ */    if (zincnt == 0) {                  /* Got nothing? */        if (ferror(fp[ZIFILE])) {            debug(F100,"ZINFILL ferror","",0);            debug(F101,"ZINFILL errno","",errno);#ifdef ZDEBUG            printf("ZINFILL errno=%d\n",errno);#endif /* ZDEBUG */#ifdef EWOULDBLOCK            return((errno == EWOULDBLOCK) ? -3 : -2);#else            return(-2);#endif /* EWOULDBLOCK */        }    /* In case feof() didn't work just above -- sometimes it doesn't... */        if (feof(fp[ZIFILE]) ) {            debug(F100,"ZINFILL count 0 EOF return -1","",0);            return (-1);        } else {            debug(F100,"ZINFILL count 0 not EOF return -2","",0);            return(-2);        }    }    zinptr = zinbuffer;    /* set pointer to beginning, (== &zinbuffer[0]) */    zincnt--;                           /* One less char in buffer */    return((int)(*zinptr++) & 0377);    /* because we return the first */}/*  Z S O U T  --  Write a string out to the given file, buffered.  */intzsout(n,s) int n; char *s; {    int rc = 0;    rc = chkfn(n);    if (rc < 1) return(-1);             /* Keep this, prevents memory faults */    if (!s) return(0);                  /* Null pointer, do nothing, succeed */    if (!*s) return(0);                 /* empty string, ditto */#ifdef IKSD    /*      This happens with client-side Kermit server when a REMOTE command      was sent from the server to the client and the server is supposed to      display the text, but of course there is no place to display it      since it is in remote mode executing Kermit protocol.    */    if (inserver && !local && (n == ZCTERM || n == ZSTDIO)) {#ifdef COMMENT        return(ttol(s,((int)strlen(s)) < 0) ? -1 : 0);#else        return(0);#endif /* COMMENT */    }#endif /* IKSD */    if (n == ZSFILE)      return(write(fileno(fp[n]),s,(int)strlen(s)));    rc = fputs(s,fp[n]) == EOF ? -1 : 0;    if (n == ZWFILE)      fflush(fp[n]);    return(rc);}/*  Z S O U T L  --  Write string to file, with line terminator, buffered  */intzsoutl(n,s) int n; char *s; {    if (zsout(n,s) < 0)        return(-1);#ifdef IKSD    if (inserver && !local && (n == ZCTERM || n == ZSTDIO)) {#ifdef COMMENT        return(ttoc(LF));#else        return(0);                      /* See comments in zsout() */#endif /* COMMENT */    }#endif /* IKSD */    if (n == ZSFILE)                    /* Session log is unbuffered */      return(write(fileno(fp[n]),"\n",1));    else if (fputs("\n",fp[n]) == EOF)      return(-1);    if (n == ZDIFIL || n == ZWFILE)     /* Flush connection log records */      fflush(fp[n]);    return(0);}/*  Z S O U T X  --  Write x characters to file, unbuffered.  */intzsoutx(n,s,x) int n, x; char *s; {#ifdef IKSD    if (inserver && !local && (n == ZCTERM || n == ZSTDIO)) {#ifdef COMMENT        return(ttol(s,x));              /* See comments in zsout() */#else        return(x);#endif /* COMMENT */    }#endif /* IKSD */#ifdef COMMENT    if (chkfn(n) < 1) return(-1);    return(write(fp[n]->_file,s,x));#endif /* COMMENT */    return(write(fileno(fp[n]),s,x) == x ? x : -1);}/*  Z C H O U T  --  Add a character to the given file.  *//*  Should return 0 or greater on success, -1 on failure (e.g. disk full)  */int#ifdef CK_ANSICzchout(register int n, char c)#elsezchout(n,c) register int n; char c;#endif /* CK_ANSIC *//* zchout() */ {    /* if (chkfn(n) < 1) return(-1); */#ifdef IKSD    if (inserver && !local && (n == ZCTERM || n == ZSTDIO)) {#ifdef COMMENT        return(ttoc(c));#else        return(0);                      /* See comments in zsout() */#endif /* COMMENT */    }#endif /* IKSD */    if (n == ZSFILE)                    /* Use unbuffered for session log */      return(write(fileno(fp[n]),&c,1) == 1 ? 0 : -1);                                /* Buffered for everything else */    if (putc(c,fp[n]) == EOF)   /* If true, maybe there was an error */      return(ferror(fp[n])?-1:0);       /* Check to make sure */    else                                /* Otherwise... */      return(0);                        /* There was no error. */}/* (PWP) buffered character output routine to speed up file IO */intzoutdump() {    int x;    char * zp;    zoutptr = zoutbuffer;               /* Reset buffer pointer in all cases */#ifdef DEBUG    if (deblog)      debug(F101,"zoutdump zoutcnt","",zoutcnt);#endif /* DEBUG */    if (zoutcnt == 0) {                 /* Nothing to output */        return(0);    } else if (zoutcnt < 0) {           /* Unexpected negative argument */        zoutcnt = 0;                    /* Reset output buffer count */        return(-1);                     /* and fail. */    }#ifdef IKSD    if (inserver && !local && fp[ZOFILE] == stdout) {#ifdef COMMENT        x = ttol(zoutbuffer,zoutcnt);#else        x = 1;                          /* See comments in zsout() */#endif /* COMMENT */        zoutcnt = 0;        return(x > 0 ? 0 : -1);    }#endif /* IKSD *//*  Frank Prindle suggested that replacing this fwrite() by an fflush()  followed by a write() would improve the efficiency, especially when  writing to stdout.  Subsequent tests showed a 5-fold improvement.*/#ifdef COMMENT    if (x = fwrite(zoutbuffer, 1, zoutcnt, fp[ZOFILE])) ...#endif /* COMMENT */#ifndef CK_NONBLOCK    fflush(fp[ZOFILE]);#endif /* CK_NONBLOCK */    zp = zoutbuffer;    while (zoutcnt > 0) {        if ((x = write(fileno(fp[ZOFILE]),zp,zoutcnt)) > -1) {#ifdef DEBUG            if (deblog)                 /* Save a function call... */              debug(F101,"zoutdump wrote","",x);#endif /* DEBUG */            zoutcnt -= x;               /* Adjust output buffer count */            zp += x;                    /* and pointer */        } else {#ifdef DEBUG            if (deblog) {                debug(F101,"zoutdump write error","",errno);                debug(F101,"zoutdump write returns","",x);            }#endif /* DEBUG */            zoutcnt = 0;                /* Reset output buffer count */            return(-1);                 /* write() failed */        }    }    return(0);}/*  C H K F N  --  Internal function to verify file number is ok  *//* Returns:  -1: File number n is out of range   0: n is in range, but file is not open   1: n in range and file is open*/intchkfn(n) int n; {    /* if (n != ZDFILE) debug(F101,"chkfn","",n); */    if (n < 0 || n >= ZNFILS) {        if (n != ZDFILE) debug(F101,"chkfn out of range","",n);        return(-1);    } else {        /* if (n != ZDFILE) debug(F101,"chkfn fp[n]","",fp[n]); */        return((fp[n] == NULL) ? 0 : 1);    }}/*  Z G E T F S -- Return file size regardless of accessibility *//*  Used for directory listings, etc.  Returns:    The size of the file in bytes, 0 or greater, if the size can be learned.    -1 if the file size can not be obtained.  Also (and this is a hack just for UNIX):    If the argument is the name of a symbolic link,    the global variable issymlink is set to 1,    and the global buffer linkname[] gets the link value.    And it sets zgfs_dir to 1 if it's a directory, otherwise 0.  This lets us avoid numerous redundant calls to stat().*/int zgfs_link = 0;int zgfs_dir = 0;time_t zgfs_mtime = 0;unsigned int zgfs_mode = 0;#ifdef CKSYMLINKchar linkname[CKMAXPATH+1];#ifndef _IFLNK#define _IFLNK 0120000#endif /* _IFLNK */#endif /* CKSYMLINK */longzgetfs(name) char *name; {    struct stat buf;    char fnam[CKMAXPATH+4];    long size = -1L;    int x;    int needrlink = 0;    char * s;    if (!name) name = "";    if (!*name) return(-1);#ifdef UNIX    x = strlen(name);    if (x == 9 && !strcmp(name,"/dev/null"))      return(0);#endif /* UNIX */    s = name;#ifdef DTILDE    if (*s == '~') {        s = tilde_expand(s);        if (!s) s = "";        if (!*s) s = name;    }#endif /* DTILDE */    x = ckstrncpy(fnam,s,CKMAXPATH);    s = fnam;    debug(F111,"zgetfs fnam",s,x);    if (x > 0 && s[x-1] == '/')      s[x-1] = '\0';    zgfs_dir = 0;                       /* Assume it's not a directory */    zgfs_link = 0;                      /* Assume it's not a symlink */    zgfs_mtime = 0;			/* No time yet */    zgfs_mode = 0;			/* No permission bits yet */#ifdef CKSYMLINK                        /* We're doing symlinks? */#ifdef USE_LSTAT                        /* OK to use lstat()? */    x = lstat(s,&buf);    debug(F101,"STAT","",1);    if (x < 0)                          /* stat() failed */      return(-1);    if (                                /* Now see if it's a symlink */#ifdef S_ISLNK        S_ISLNK(buf.st_mode)#else#ifdef _IFLNK        ((_IFMT & buf.st_mode) == _IFLNK)#endif /* _IFLNK */#endif /* S_ISLNK */        ) {        zgfs_link = 1;                  /* It's a symlink */        linkname[0] = '\0';             /* Get the name */        x = readlink(s,linkname,CKMAXPATH);        debug(F101,"zgetfs readlink",s,x);        if (x > -1 && x < CKMAXPATH) {  /* It's a link */            linkname[x] = '\0';            size = buf.st_size;         /* Remember size of link */            x = stat(s,&buf);           /* Now stat the linked-to file */	    debug(F101,"STAT","",2);            if (x < 0)                  /* so we can see if it's a directory */              return(-1);        } else {            ckstrncpy(linkname,"(lookup failed)",CKMAXPATH);        }    }#else  /* !USE_LSTAT */    x = stat(s,&buf);                   /* No lstat(), use stat() instead */    debug(F101,"STAT","",3);    if (x < 0)      return(-1);#endif /* USE_LSTAT */    /* Do we need to call readlink()? */#ifdef NOLINKBITS/*  lstat() does not work in SCO operating systems.  From "man NS lstat":  lstat obtains information about the file named by path. In the case of a  symbolic link, lstat returns information about the link, and not the file  named by the link. It is only used by the NFS automount daemon and should  not be utilized by users.*/    needrlink = 1;    debug(F101,"zgetfs forced needrlink","",needrlink);#else#ifdef S_ISLNK    needrlink = S_ISLNK(buf.st_mode);    debug(F101,"zgetfs S_ISLNK needrlink","",needrlink);#else#ifdef _IFLNK    needrlink = (_IFMT & buf.st_mode) == _IFLNK;    debug(F101,"zgetfs _IFLNK needrlink","",needrlink);#else    needrlink = 1;    debug(F101,"zgetfs default needrlink","",needrlink);#endif /* _IFLNK */#endif /* S_ISLNK */#endif /* NOLINKBITS */    if (needrlink) {        linkname[0] = '\0';        errno = 0;        x = readlink(s,linkname,CKMAXPATH);#ifdef DEBUG        debug(F111,"zgetfs readlink",s,x);        if (x < 0)          debug

⌨️ 快捷键说明

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