Annotation of 43BSD/contrib/icon/rt/host.c, revision 1.1.1.1

1.1       root        1: #include "../h/rt.h"
                      2: #include <stdio.h>
                      3: 
                      4: #ifdef UNAME
                      5: #include <sys/utsname.h>
                      6: #endif UNAME
                      7: 
                      8: /*
                      9:  * iconhost - return some sort of host name into the buffer pointed at
                     10:  *  by hostname.  This code accommodates several different host name
                     11:  *  fetching schemes.
                     12:  */
                     13: iconhost(hostname)
                     14: char *hostname;
                     15:    {
                     16: #ifdef WHOHOST
                     17:    /*
                     18:     * The host name is in /usr/include/whoami.h. (V7, 4.[01]bsd)
                     19:     */
                     20:    whohost(hostname);
                     21: #endif WHOHOST
                     22: 
                     23: #ifdef UNAME
                     24:    {
                     25:    /*
                     26:     * Use the uname system call.  (System III & V)
                     27:     */
                     28:    struct utsname uts;
                     29:    uname(&uts);
                     30:    strcpy(hostname,uts.nodename);
                     31:    }
                     32: #endif UNAME
                     33: 
                     34: #ifdef GETHOST
                     35:    /*
                     36:     * Use the gethostname system call.  (4.2bsd)
                     37:     */
                     38:    gethostname(hostname,MAXSTRING);
                     39: #endif GETHOST
                     40: 
                     41: #ifdef HOSTSTR
                     42:    /*
                     43:     * The string constant HOSTSTR contains the host name.
                     44:     */
                     45:    strcpy(hostname,HOSTSTR);
                     46: #endif HOSTSTR
                     47:    }
                     48: 
                     49: #ifdef WHOHOST
                     50: #define   HDRFILE "/usr/include/whoami.h"
                     51: /*
                     52:  * whohost - look for a line of the form
                     53:  *  #define sysname "name"
                     54:  * in HDRFILE and return the name.
                     55:  */
                     56: whohost(hostname)
                     57: char *hostname;
                     58:    {
                     59:    char buf[BUFSIZ];
                     60:    FILE *fd;
                     61: 
                     62:    fd = fopen(HDRFILE, "r");
                     63:    if (fd == NULL) {
                     64:       sprintf(buf, "Cannot open %s, no value for &host\n", HDRFILE);
                     65:       syserr(buf);
                     66:    }
                     67:    setbuf(fd,NULL);
                     68: 
                     69:    for (;;) {   /* each line in the file */
                     70:       if (fgets(buf, sizeof buf, fd) == NULL) {
                     71:          sprintf(buf, "No #define for sysname in %s, no value for &host\n", HDRFILE);
                     72:          syserr(buf);
                     73:       }
                     74:       if (sscanf(buf,"#define sysname \"%[^\"]\"", hostname) == 1) {
                     75:          fclose(fd);
                     76:          return;
                     77:       }
                     78:    }
                     79:    }
                     80: #endif WHOHOST

unix.superglobalmegacorp.com

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