Annotation of researchv10dc/cmd/icon/src/iconx/rsys.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * File: rsys.c
        !             3:  *  Contents: getstr, host, putstr
        !             4:  */
        !             5: 
        !             6: #include "../h/rt.h"
        !             7: 
        !             8: /*
        !             9:  * getstr - read a line into buf from file fd.  At most maxi characters
        !            10:  *  are read.  getstr returns the length of the line, not counting
        !            11:  *  the newline.
        !            12:  */
        !            13: 
        !            14: getstr(buf, maxi, fd)
        !            15: register char *buf;
        !            16: int maxi;
        !            17: FILE *fd;
        !            18:    {
        !            19:    register int c, l;
        !            20: 
        !            21:    l = 0;
        !            22:    while ((c = getc(fd)) != '\n') {
        !            23:       if (c == EOF)
        !            24:         if (l > 0) return l;
        !            25:         else return -1;
        !            26:       *buf++ = c;
        !            27:       if (++l >= maxi)
        !            28:          break;
        !            29:       }
        !            30:    return l;
        !            31:    }
        !            32: 
        !            33: 
        !            34: #ifdef UtsName
        !            35: #include <sys/utsname.h>
        !            36: #endif UtsName
        !            37: 
        !            38: /*
        !            39:  * iconhost - return some sort of host name into the buffer pointed at
        !            40:  *  by hostname.  This code accommodates several different host name
        !            41:  *  fetching schemes.
        !            42:  */
        !            43: iconhost(hostname)
        !            44: char *hostname;
        !            45:    {
        !            46: #ifdef WhoHost
        !            47:    /*
        !            48:     * The host name is in /usr/include/whoami.h. (V7, 4.[01]bsd)
        !            49:     */
        !            50:    whohost(hostname);
        !            51: #endif WhoHost
        !            52: 
        !            53: #ifdef UtsName
        !            54:    {
        !            55:    /*
        !            56:     * Use the uname system call.  (System III & V)
        !            57:     */
        !            58:    struct utsname uts;
        !            59:    uname(&uts);
        !            60:    strcpy(hostname,uts.nodename);
        !            61:    }
        !            62: #endif UtsName
        !            63: 
        !            64: #ifdef GetHost
        !            65:    /*
        !            66:     * Use the gethostname system call.  (4.2bsd)
        !            67:     */
        !            68:    gethostname(hostname,MaxCvtLen);
        !            69: #endif GetHost
        !            70: 
        !            71: #ifdef VMS
        !            72:    /*
        !            73:     * VMS has its own special logic
        !            74:     */
        !            75:    char *h;
        !            76:    if (!(h = getenv("ICON$HOST")) && !(h = getenv("SYS$NODE")))
        !            77:       h = "VAX/VMS";
        !            78:    strcpy(hostname,h);
        !            79: #endif VMS
        !            80: 
        !            81: #ifdef HostStr
        !            82:    /*
        !            83:     * The string constant HostStr contains the host name.
        !            84:     */
        !            85:    strcpy(hostname,HostStr);
        !            86: #endif HostStr
        !            87:    }
        !            88: 
        !            89: #ifdef WhoHost
        !            90: #define HdrFile "/usr/include/whoami.h"
        !            91: /*
        !            92:  * whohost - look for a line of the form
        !            93:  *  #define sysname "name"
        !            94:  * in HdrFile and return the name.
        !            95:  */
        !            96: whohost(hostname)
        !            97: char *hostname;
        !            98:    {
        !            99:    char buf[BUFSIZ];
        !           100:    FILE *fd;
        !           101: 
        !           102:    fd = fopen(HdrFile, "r");
        !           103:    if (fd == NULL) {
        !           104:       sprintf(buf, "Cannot open %s, no value for &host\n", HdrFile);
        !           105:       syserr(buf);
        !           106:    }
        !           107: #ifndef VMS
        !           108:    setbuf(fd,NULL);
        !           109: #endif VMS
        !           110: 
        !           111:    for (;;) {   /* each line in the file */
        !           112:       if (fgets(buf, sizeof buf, fd) == NULL) {
        !           113:          sprintf(buf, "No #define for sysname in %s, no value for &host\n", HdrFile);
        !           114:          syserr(buf);
        !           115:       }
        !           116:       if (sscanf(buf,"#define sysname \"%[^\"]\"", hostname) == 1) {
        !           117:          fclose(fd);
        !           118:          return;
        !           119:       }
        !           120:    }
        !           121:    }
        !           122: #endif WhoHost
        !           123: 
        !           124: 
        !           125: /*
        !           126:  * Print l characters starting at s on file f.
        !           127:  */
        !           128: 
        !           129: putstr(f, s, l)
        !           130: register FILE *f;
        !           131: register char *s;
        !           132: register word l;
        !           133:    {
        !           134:    while (l--)
        !           135:       putc(*s++, f);
        !           136:    }

unix.superglobalmegacorp.com

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