|
|
1.1 root 1: /*
2: * This software is Copyright (c) 1986 by Rick Adams.
3: *
4: * Permission is hereby granted to copy, reproduce, redistribute or
5: * otherwise use this software as long as: there is no monetary
6: * profit gained specifically from the use or reproduction or this
7: * software, it is not sold, rented, traded or otherwise marketed, and
8: * this copyright notice is included prominently in any copy
9: * made.
10: *
11: * The author make no claims as to the fitness or correctness of
12: * this software for any use whatsoever, and it is provided as is.
13: * Any use of this software is at the user's own risk.
14: *
15: * This routine is compatible with the Unix T/S system call uname,
16: * which figures out the name of the local system.
17: * However, we do it by reading the file /usr/include/whoami.h.
18: * This avoids having to recompile uucp for each site and hence
19: * avoids having to distribute the source to uucp to people who
20: * have only binary licenses.
21: */
22:
23: #ifdef SCCSID
24: static char *SccsId = "@(#)uname.c 2.16 9/24/87";
25: #endif /* SCCSID */
26:
27: #ifdef BSD2_10
28: #include <shortnames.h>
29: #endif /* BSD2_10 */
30:
31: #include "params.h"
32:
33: #ifdef UNAME
34: # define DONE
35: #endif /* UNAME */
36:
37: #ifdef GHNAME
38: uname(uptr)
39: struct utsname *uptr;
40: {
41: char *cp;
42: extern char *mydomain();
43: gethostname(uptr->nodename, sizeof (uptr->nodename));
44: cp = mydomain();
45: if (*cp == '\0') /* get domain name from hostname */
46: return;
47: cp = index(uptr->nodename, '.');
48: if (cp)
49: *cp = '\0';
50: }
51: # define DONE
52: #endif
53:
54: #ifdef UUNAME
55: uname(uptr)
56: struct utsname *uptr;
57: {
58: FILE *uucpf;
59: register char *p;
60: /* uucp name is stored UUNAME */
61:
62: if (((uucpf = fopen(UUNAME, "r")) == NULL) ||
63: fgets(uptr->nodename, sizeof (uptr->nodename), uucpf) == NULL) {
64: fprintf(stderr, "no sysname in %s\n", UUNAME);
65: return;
66: }
67: p = index(uptr->nodename, '\n');
68: if (p)
69: *p = '\0';
70: if (uucpf != NULL)
71: fclose(uucpf);
72: }
73: #define DONE
74: #endif /* UUNAME */
75:
76: #ifndef DONE
77: #define HDRFILE "/usr/include/whoami.h"
78:
79: uname(uptr)
80: struct utsname *uptr;
81: {
82: char buf[BUFSIZ];
83: FILE *fd;
84:
85: fd = fopen(HDRFILE, "r");
86: if (fd == NULL) {
87: fprintf(stderr, "Cannot open %s\n", HDRFILE);
88: exit(1);
89: }
90:
91: for (;;) { /* each line in the file */
92: if (fgets(buf, sizeof buf, fd) == NULL) {
93: fprintf(stderr, "no sysname in %s\n", HDRFILE);
94: fclose(fd);
95: exit(2);
96: }
97: if (sscanf(buf, "#define sysname \"%[^\"]\"", uptr->nodename) == 1) {
98: fclose(fd);
99: return;
100: }
101: }
102: }
103: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.