BSD 4_2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 11 May 1983 14:35:55 +0000 (06:35 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 11 May 1983 14:35:55 +0000 (06:35 -0800)
Work on file usr/src/new/new/icon/cmp/lib/host.c

Synthesized-from: CSRG/cd1/4.2

usr/src/new/new/icon/cmp/lib/host.c [new file with mode: 0644]

diff --git a/usr/src/new/new/icon/cmp/lib/host.c b/usr/src/new/new/icon/cmp/lib/host.c
new file mode 100644 (file)
index 0000000..c6d7fbf
--- /dev/null
@@ -0,0 +1,60 @@
+#include "../h/config.h"
+#include "../h/rt.h"
+#include <stdio.h>
+
+#ifdef UNAME
+#include <sys/utsname.h>
+#endif UNAME
+
+iconhost(hostname)
+char *hostname;
+{
+#ifdef WHOHOST
+       whohost(hostname);
+#endif WHOHOST
+
+#ifdef UNAME
+       {
+       struct utsname *uptr;
+       uname(utsname);
+       strcpy(hostname,uptr->nodename);
+       }
+#endif UNAME
+
+#ifdef GETHOST
+       gethostname(hostname, MAXSTRING);
+#endif GETHOST
+
+#ifdef HOSTSTR
+       strcpy(hostname,HOSTSTR);
+#endif HOSTSTR
+}
+
+#ifdef WHOHOST
+#define        HDRFILE "/usr/include/whoami.h"
+
+whohost(hostname)
+char *hostname;
+{
+       char buf[BUFSIZ];
+       FILE *fd;
+
+       fd = fopen(HDRFILE, "r");
+       if (fd == NULL) {
+               sprintf(buf, "Cannot open %s, no value for &host\n", HDRFILE);
+               syserr(buf);
+       }
+       setbuf(fd,NULL);
+
+       for (;;) {      /* each line in the file */
+               if (fgets(buf, sizeof buf, fd) == NULL) {
+                       sprintf(buf, "No #define for sysname in %s, no value for &host\n", HDRFILE);
+                       syserr(buf);
+               }
+               if (sscanf(buf,"#define sysname \"%[^\"]\"", hostname) == 1) {
+                       fclose(fd);
+                       return;
+               }
+       }
+}
+#endif WHOHOST