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

📄 ckufio.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#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;#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;    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 {            strcpy(linkname,"(lookup failed)");        }    }#else  /* !USE_LSTAT */    x = stat(s,&buf);                   /* No lstat(), use stat() instead */    debug(F101,"STAT","",3);    if (x < 0)      return(-1);#endif /* USE_STAT */    /* 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(F101,"zgetfs readlink errno","",errno);        else          debug(F110,"zgetfs readlink result",linkname,0);#endif /* DEBUG */        if (x > -1 && x < CKMAXPATH) {            zgfs_link = 1;            linkname[x] = '\0';        }    }#else  /* !CKSYMLINK */    x = stat(s,&buf);                   /* Just stat the file */    debug(F101,"STAT","",4);    if (x < 0)                          /* and get the size */      return(-1);#endif /* CKSYMLINK */    zgfs_mtime = buf.st_mtime;    zgfs_mode = buf.st_mode;    zgfs_dir = (S_ISDIR(buf.st_mode)) ? 1 : 0; /* Set "is directory" flag */    return((size < 0L) ? buf.st_size : size); /* Return the size */}/*  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;    char * s;    int x, itsadir = 0;    extern int zchkid;    if (!name)      return(-1);    x = strlen(name);    if (x < 1)      return(-1);    s = name;#ifdef UNIX    if (x == 9 && !strcmp(s,"/dev/null"))      return(0);#endif /* UNIX */#ifdef DTILDE    if (*s == '~') {        s = tilde_expand(s);        if (!s) s = "";        if (!*s) s = name;    }#endif /* DTILDE */    x = stat(s,&buf);    debug(F101,"STAT","",5);    if (x < 0) {        debug(F111,"zchki stat fails",s,errno);        return(-1);    }    if (S_ISDIR (buf.st_mode))      itsadir = 1;    if (!(itsadir && zchkid)) {         /* Unless this... */        if (!S_ISREG (buf.st_mode)      /* Must be regular file */#ifdef S_ISFIFO            && !S_ISFIFO (buf.st_mode)  /* or FIFO */#endif /* S_ISFIFO */            ) {            debug(F111,"zchki not regular file",s,x);            return(-2);        }    }    debug(F111,"zchki stat ok:",s,x);#ifdef SW_ACC_ID    debug(F100,"zchki swapping ids for access()","",0);    priv_on();#endif /* SW_ACC_ID */    x = access(s,R_OK);#ifdef SW_ACC_ID    priv_off();    debug(F100,"zchki swapped ids restored","",0);#endif /* SW_ACC_ID */    if (x < 0) {                        /* Is the file accessible? */        debug(F111,"zchki access failed:",s,x); /* No */        return(-3);    } else {        iflen = buf.st_size;            /* Yes, remember size */        ckstrncpy(nambuf,s,CKMAXPATH);  /* and name globally. */        debug(F111,"zchki access ok:",s,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.  NOTE: The design is flawed.  There is no distinction among:   . Can I overwrite an existing file?   . Can I create a file (or directory) in an existing directory?   . Can I create a file (or directory) and its parent(s)?*/intzchko(name) char *name; {    int i, x, itsadir = 0;    char *s;    extern int zchkod;                  /* Used by IF WRITEABLE */    if (!name) return(-1);              /* Watch out for null pointer. */    x = (int)strlen(name);              /* Get length of filename */    debug(F111,"zchko",name,zchkod);#ifdef UNIX/*  Writing to null device is OK.*/    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 */    name = s;    s = NULL;/*  zchkod is a global flag meaning we're checking not to see if the directory  file is writeable, but if it's OK to create files IN the directory.*/    if (!zchkod && isdir(name))         /* Directories are not writeable */      return(-1);    s = malloc(x+3);                    /* Must copy because we can't */    if (!s) {                           /* write into our argument. */        fprintf(stderr,"zchko: Malloc error 46\n");        return(-1);    }    strcpy(s,name);    for (i = x; i > 0; i--) {           /* Strip filename from right. */        if (ISDIRSEP(s[i-1])) {            itsadir = 1;            break;        }    }    debug(F101,"zchko i","",i);    debug(F101,"zchko itsadir","",itsadir);#ifdef COMMENT/* X/OPEN XPG3-compliant systems fail if argument ends with "/"...  */    if (i == 0)                         /* If no path, use current directory */      strcpy(s,"./")

⌨️ 快捷键说明

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