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

📄 ckufio.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#else#ifdef IRIX60#define HAVEUTMPX#else#ifdef CK_SCOV5#define HAVEUTMPX#else#ifdef HPUX100#define HAVEUTMPX#else#ifdef UNIXWARE#define HAVEUTMPX#endif /* UNIXWARE */#endif /* HPUX100 */#endif /* CK_SCOV5 */#endif /* IRIX60 */#endif /* SOLARIS */#endif /* HAVEUTMPX */#ifdef HAVEUTMPX#include <utmpx.h>#else#ifdef OSF50/* Because the time_t in the utmp struct is 64 bits but time() wants 32 */#define __V40_OBJ_COMPAT 1#endif /* OSF50 */#include <utmp.h>#ifdef OSF50#undef __V40_OBJ_COMPAT#endif /* OSF50 */#endif /* HAVEUTMPX */#endif /* UTMPBUG */#ifndef WTMPFILE#ifdef QNX#define WTMPFILE "/usr/adm/wtmp.1"#else#ifdef LINUX#define WTMPFILE "/var/log/wtmp"#else#define WTMPFILE "/usr/adm/wtmp"#endif /* QNX */#endif /* LINUX */#endif /* WTMPFILE */char * wtmpfile = NULL;static int wtmpfd = 0;static char cksysline[32] = { NUL, NUL };#ifndef HAVEUTHOST                      /* Does utmp include ut_host[]? */#ifdef HAVEUTMPX                        /* utmpx always does */#define HAVEUTHOST#else#ifdef LINUX                            /* Linux does */#define HAVEUTHOST#else#ifdef SUNOS4                           /* SunOS does */#define HAVEUTHOST#else#ifdef AIX41                            /* AIX 4.1 and later do */#define HAVEUTHOST#endif /* AIX41 */#endif /* SUNOS4 */#endif /* LINUX */#endif /* HAVEUTMPX */#endif /* HAVEUTHOST */#ifdef UW200PID_T _vfork() {                        /* To satisfy a library foulup */    return(fork());                     /* in Unixware 2.0.x */}#endif /* UW200 */VOID#ifdef CK_ANSIClogwtmp(const char * line, const char * name, const char * host)#elselogwtmp(line, name, host) char *line, *name, *host;#endif /* CK_ANSIC *//* logwtmp */ {#ifdef HAVEUTMPX    struct utmpx ut;                    /* Needed for ut_host[] */#else    struct utmp ut;#endif /* HAVEUTMPX */    struct stat buf;    /* time_t time(); */    if (!ckxwtmp)      return;    if (!wtmpfile)      makestr(&wtmpfile,WTMPFILE);    if (!line) line = "";    if (!name) name = "";    if (!host) host = "";    if (!wtmpfd && (wtmpfd = open(wtmpfile, O_WRONLY|O_APPEND, 0)) < 0) {        ckxwtmp = 0;        debug(F110,"WTMP open failed",line,0);        return;    }    if (!fstat(wtmpfd, &buf)) {        ckstrncpy(ut.ut_line, line, sizeof(ut.ut_line));        ckstrncpy(ut.ut_name, name, sizeof(ut.ut_name));#ifdef HAVEUTHOST        /* Not portable */        ckstrncpy(ut.ut_host, host, sizeof(ut.ut_host));#endif /* HAVEUTHOST */#ifdef HAVEUTMPX        time(&ut.ut_tv.tv_sec);#else#ifdef LINUX/* In light of the following comment perhaps the previous line should *//* be "#ifndef COMMENT". */        {            /*             * On 64-bit platforms sizeof(time_t) and sizeof(ut.ut_time)             * are not the same and attempt to use an address of             * ut.ut_time as an argument to time() call may cause             * "unaligned access" trap.             */            time_t zz;            time(&zz);            ut.ut_time = zz;        }#else        time(&ut.ut_time);#endif /* LINUX */#endif /* HAVEUTMPX */        if (write(wtmpfd, (char *)&ut, sizeof(struct utmp)) !=            sizeof(struct utmp)) {#ifndef NOFTRUNCATE#ifndef COHERENT            ftruncate(wtmpfd, buf.st_size); /* Error, undo any partial write */#else            chsize(wtmpfd, buf.st_size); /* Error, undo any partial write */#endif /* COHERENT */#endif /* NOFTRUNCATE */            debug(F110,"WTMP write error",line,0);        } else {            debug(F110,"WTMP record OK",line,0);            return;        }    }}#endif /* CKWTMP */#ifdef CKSYSLOG/*  C K S Y S L O G  --  C-Kermit system logging function,  For use by other modules.  This module can, but doesn't have to, use it.  Call with:    n = SYSLG_xx values defined in ckcdeb.h    s1, s2, s3: strings.*/VOIDcksyslog(n, m, s1, s2, s3) int n, m; char * s1, * s2, * s3; {    int level;    if (!ckxlogging)                    /* syslogging */      return;    if (!s1) s1 = "";                   /* Fix null args */    if (!s2) s2 = "";    if (!s3) s3 = "";    switch (n) {                        /* Translate Kermit level */      case SYSLG_DB:                    /* to syslog level */        level = LOG_DEBUG;        break;      default:        level = m ? LOG_INFO : LOG_ERR;    }    debug(F110,"cksyslog s1",s1,0);    debug(F110,"cksyslog s2",s2,0);    debug(F110,"cksyslog s3",s3,0);    errno = 0;    syslog(level, "%s: %s %s", s1, s2, s3); /* Write syslog record */    debug(F101,"cksyslog errno","",errno);}#endif /* CKSYSLOG *//* Declarations */int maxnam = MAXNAMLEN;                 /* Available to the outside */int maxpath = MAXPATH;int ck_znewn = -1;#ifdef UNIXchar startupdir[MAXPATH+1];#endif /* UNIX */int pexitstat = -2;                     /* Process exit status */FILE *fp[ZNFILS] = {                    /* File pointers */   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};/* Flags for each file indicating whether it was opened with popen() */int ispipe[ZNFILS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };/* Buffers and pointers used in buffered file input and output. */#ifdef DYNAMICextern char *zinbuffer, *zoutbuffer;#elseextern char zinbuffer[], zoutbuffer[];#endif /* DYNAMIC */extern char *zinptr, *zoutptr;extern int zincnt, zoutcnt;extern int wildxpand;static long iflen = -1L;                /* Input file length */static PID_T pid = 0;                   /* pid of child fork */static int fcount = 0;                  /* Number of files in wild group */static int nxpand = 0;                  /* Copy of fcount */static char nambuf[CKMAXPATH+4];        /* Buffer for a pathname */#ifndef NOFRILLSstatic char zmbuf[200];                 /* For mail, remote print strings */#endif /* NOFRILLS */char **mtchs = NULL;                    /* Matches found for filename */char **mtchptr = NULL;                  /* Pointer to current match *//*  Z K S E L F  --  Kill Self: log out own job, if possible.  *//* Note, should get current pid, but if your system doesn't have *//* getppid(), then just kill(0,9)...  */#ifndef SVR3#ifndef POSIX#ifndef OSFPC/* Already declared in unistd.h for SVR3 and POSIX */#ifdef CK_ANSICextern PID_T getppid(void);#else#ifndef PS2AIX10#ifndef COHERENTextern PID_T getppid();#endif /* COHERENT */#endif /* PS2AIX10 */#endif /* CK_ANSIC */#endif /* OSFPC */#endif /* POSIX */#endif /* SVR3 */intzkself() {                              /* For "bye", but no guarantee! */#ifdef PROVX1    return(kill(0,9));#else#ifdef V7    return(kill(0,9));#else#ifdef TOWER1    return(kill(0,9));#else#ifdef FT18    return(kill(0,9));#else#ifdef aegis    return(kill(0,9));#else#ifdef COHERENT    return(kill((PID_T)getpid(),1));#else#ifdef PID_T    exit(kill((PID_T)getppid(),1));    return(0);#else    exit(kill(getppid(),1));    return(0);#endif#endif#endif#endif#endif#endif#endif}static VOIDgetfullname(name) char * name; {    char *p = (char *)fullname;    int len = 0;    fullname[0] = '\0';    /* If necessary we could also chase down symlinks here... */#ifdef COMMENT    /* This works but is incompatible with wuftpd */    if (isguest && anonroot) {        ckstrncpy(fullname,anonroot,CKMAXPATH);        len = strlen(fullname);        if (len > 0)          if (fullname[len-1] == '/')            len--;    }    p += len;#endif /* COMMENT */    zfnqfp(name, CKMAXPATH - len, p);    while (*p) {        if (*p < '!') *p = '_';        p++;    }}/*  D O I K L O G  --  Open Kermit-specific ftp-like transfer log. */static VOIDdoiklog() {    if (iklogopen)                      /* Already open? */      return;    if (xferlog) {                      /* Open iksd log if requested */        if (!xferfile)                  /* If no pathname given */          xferfile = XFERFILE;          /* use this default */        if (*xferfile) {            xferlog = open(xferfile, O_WRONLY | O_APPEND | O_CREAT, 0660);            debug(F101,"doiklog open","",xferlog);            if (xferlog < 0) {#ifdef CKSYSLOG                syslog(LOG_ERR, "xferlog open failure %s: %m", xferfile);#endif /* CKSYSLOG */                debug(F101,"doiklog open errno","",errno);                xferlog = 0;            } else              iklogopen = 1;        } else          xferlog = 0;#ifdef CKSYSLOG        if (xferlog && ckxlogging)          syslog(LOG_INFO, "xferlog: %s open ok", xferfile);#endif /* CKSYSLOG */    }}/*  Z O P E N I  --  Open an existing file for input. *//* Returns 1 on success, 0 on failure */intzopeni(n,name) int n; char *name; {    int x, y;    debug(F111,"zopeni name",name,n);    /* debug(F101,"zopeni fp","", (unsigned) fp[n]); */    if (chkfn(n) != 0) return(0);    zincnt = 0;                         /* Reset input buffer */    if (n == ZSYSFN) {                  /* Input from a system function? *//*** Note, this function should not be called with ZSYSFN ***//*** Always call zxcmd() directly, and give it the real file number ***//*** you want to use.  ***/        debug(F110,"zopeni called with ZSYSFN, failing!",name,0);        *nambuf = '\0';                 /* No filename. */        return(0);                      /* fail. */#ifdef COMMENT        return(zxcmd(n,name));          /* Try to fork the command */#endif    }    if (n == ZSTDIO) {                  /* Standard input? */        if (is_a_tty(0)) {            fprintf(stderr,"Terminal input not allowed");            debug(F110,"zopeni: attempts input from unredirected stdin","",0);            return(0);        }        fp[ZIFILE] = stdin;        ispipe[ZIFILE] = 0;        return(1);    }    fp[n] = fopen(name,"r");            /* Real file, open it. */    debug(F111,"zopeni fopen", name, fp[n]);#ifdef ZDEBUG    printf("ZOPENI fp[%d]=%ld\n",n,fp[n]);#endif /* ZDEBUG */    ispipe[n] = 0;    if (xferlog#ifdef CKSYSLOG        || ckxsyslog >= SYSLG_FA && ckxlogging#endif /* CKSYSLOG */        ) {        getfullname(name);        debug(F110,"zopeni fullname",fullname,0);    }    if (fp[n] == NULL) {#ifdef CKSYSLOG        if (ckxsyslog >= SYSLG_FA && ckxlogging)          syslog(LOG_INFO, "file[%d] %s: open failed (%m)", n, fullname);        perror(fullname);#else        perror(name);#endif /* CKSYSLOG */        return(0);    } else {#ifdef CKSYSLOG        if (ckxsyslog >= SYSLG_FA && ckxlogging)          syslog(LOG_INFO, "file[%d] %s: open read ok", n, fullname);#endif /* CKSYSLOG */        clearerr(fp[n]);        return(1);    }}#ifdef QNX#define DONDELAY#else#ifdef O_NDELAY#define DONDELAY#endif /* O_NDELAY */#endif /* QNX *//*  Z O P E N O  --  Open a new file for output.  */intzopeno(n,name,zz,fcb)/* zopeno */  int n; char *name; struct zattr *zz; struct filinfo *fcb; {    char p[8];    int append = 0;/* As of Version 5A, the attribute structure and the file information *//* structure are included in the arglist. */#ifdef DEBUG    debug(F111,"zopeno",name,n);    if (fcb) {        debug(F101,"zopeno fcb disp","",fcb->dsp);        debug(F101,"zopeno fcb type","",fcb->typ);        debug(F101,"zopeno fcb char","",fcb->cs);    } else {        debug(F100,"zopeno fcb is NULL","",0);    }#endif /* DEBUG */    if (chkfn(n) != 0)                  /* Already open? */      return(0);                        /* Nothing to do. */    if ((n == ZCTERM) || (n == ZSTDIO)) { /* Terminal or standard output */        fp[ZOFILE] = stdout;        ispipe[ZOFILE] = 0;#ifdef COMMENT	/* This seems right but it breaks client server ops */	fp[n] = stdout;        ispipe[n] = 0;#endif /* COMMENT */#ifdef DEBUG        if (n != ZDFILE)          debug(F101,"zopeno fp[n]=stdout","",fp[n]);#endif /* DEBUG */        zoutcnt = 0;        zoutptr = zoutbuffer;        return(1);    }/* A real file.  Open it in desired mode (create or append). */

⌨️ 快捷键说明

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