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.9	1/20/86";
  25: #endif /* SCCSID */
  26: 
  27: #include "params.h"
  28: 
  29: #ifdef UNAME
  30: # define DONE
  31: #endif /* UNAME */
  32: 
  33: #ifdef GHNAME
  34: uname(uptr)
  35: struct utsname *uptr;
  36: {
  37:     char *cp;
  38:     gethostname(uptr->nodename, sizeof (uptr->nodename));
  39:     cp = index(uptr->nodename, '.');
  40:     if (cp)
  41:         *cp = '\0';
  42: }
  43: # define DONE
  44: #endif
  45: 
  46: #ifdef  UUNAME
  47: uname(uptr)
  48: struct utsname *uptr;
  49: {
  50:     FILE *uucpf;
  51:     register char *p;
  52:     /* uucp name is stored in /etc/uucpname or /local/uucpname */
  53: 
  54:     if (((uucpf = fopen("/etc/uucpname", "r")) == NULL &&
  55:          (uucpf = fopen("/local/uucpname", "r")) == NULL) ||
  56:         fgets(uptr->nodename, sizeof (uptr->nodename), uucpf) == NULL) {
  57:             fprintf(stderr, "no sysname in %s\n", "/etc/uucpname");
  58:             return;
  59:     }
  60:     p = index(uptr->nodename, '\n');
  61:     if (p)
  62:         *p = '\0';
  63:     if (uucpf != NULL)
  64:         fclose(uucpf);
  65: }
  66: #define DONE
  67: #endif /* UUNAME */
  68: 
  69: #ifndef DONE
  70: #define HDRFILE "/usr/include/whoami.h"
  71: 
  72: uname(uptr)
  73: struct utsname *uptr;
  74: {
  75:     char buf[BUFSIZ];
  76:     FILE *fd;
  77: 
  78:     fd = fopen(HDRFILE, "r");
  79:     if (fd == NULL) {
  80:         fprintf(stderr, "Cannot open %s\n", HDRFILE);
  81:         exit(1);
  82:     }
  83: 
  84:     for (;;) {  /* each line in the file */
  85:         if (fgets(buf, sizeof buf, fd) == NULL) {
  86:             fprintf(stderr, "no sysname in %s\n", HDRFILE);
  87:             fclose(fd);
  88:             exit(2);
  89:         }
  90:         if (sscanf(buf, "#define sysname \"%[^\"]\"", uptr->nodename) == 1) {
  91:             fclose(fd);
  92:             return;
  93:         }
  94:     }
  95: }
  96: #endif

Defined functions

Defined variables

SccsId defined in line 24; never used

Defined macros

DONE defined in line 66; used 1 times
  • in line 69
HDRFILE defined in line 70; used 3 times
Last modified: 1986-01-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1049
Valid CSS Valid XHTML 1.0 Strict