Annotation of researchv10no/cmd/nupas/smtp/netio.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char *sccsid = "@(#)netio.c     1.7 87/07/31";
        !             3: #endif lint
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include <setjmp.h>
        !             7: #include <sysexits.h>
        !             8: 
        !             9: #include "smtp.h"
        !            10: 
        !            11: char *strcpy(), *strncat();
        !            12: 
        !            13: int
        !            14: tgets(line, size, fi)          /* fgets from TCP */
        !            15: char *line;
        !            16: int size;
        !            17: FILE *fi;
        !            18: {
        !            19:        register char *cr, *rp;
        !            20: 
        !            21:        *line = 0;
        !            22:        rp = fgets(line, size, fi);
        !            23:        if (ferror(fi)) {
        !            24:                perror("error reading from smtp");
        !            25:                bomb(EX_IOERR);
        !            26:        }
        !            27:        if (feof(fi)) {
        !            28:                perror("eof from smtp");
        !            29:                bomb(EX_IOERR);
        !            30:        }
        !            31:        if (rp==NULL) {
        !            32:                perror("Eof reading from smtp");
        !            33:                bomb(EX_IOERR);
        !            34:        }
        !            35: 
        !            36:        /* convert \r\n -> \n */
        !            37:        cr = line + strlen(line) - 2;
        !            38:        if (cr >= line && *cr == '\r' && *(cr+1) == '\n') {     /* CRLF there? */
        !            39:                *cr++ = '\n';
        !            40:                *cr = 0;
        !            41:        } else                          /* no CRLF present */
        !            42:                cr += 2;                /* point at NUL byte */
        !            43: 
        !            44:        if (feof(fi)) {
        !            45:                perror("read eof from smtp");
        !            46:                bomb(EX_IOERR);
        !            47:        }
        !            48:        return cr - line;
        !            49: }
        !            50: 
        !            51: int
        !            52: tputs(line, fo)                        /* fputs to TCP */
        !            53: char *line;
        !            54: FILE *fo;
        !            55: {
        !            56:        char buf[MAXSTR];
        !            57:        register char *nl;
        !            58: 
        !            59:        (void) strcpy(buf, line);
        !            60:        /* replace terminating \n by \r\n */
        !            61:        nl = buf + strlen(buf) - 1;             /* presumably \n */
        !            62:        if (nl >= buf && *nl=='\n') {           /* if it is ... */
        !            63:                *nl++ = '\r';
        !            64:                *nl++ = '\n';
        !            65:                *nl = 0;
        !            66:        } else
        !            67:                printf("unterminated line: <%s>\n", buf);
        !            68: 
        !            69:        (void) fputs(buf, fo);
        !            70:        (void) fflush(fo);
        !            71:        if (ferror(fo)) {
        !            72:                perror("error writing to smtp");
        !            73:                bomb(EX_IOERR);
        !            74:        }
        !            75:        return 0;
        !            76: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.