1: /*-
   2:  * Copyright (c) 1993
   3:  *	The Regents of the University of California.  All rights reserved.
   4:  *
   5:  * Redistribution and use in source and binary forms, with or without
   6:  * modification, are permitted provided that the following conditions
   7:  * are met:
   8:  * 1. Redistributions of source code must retain the above copyright
   9:  *    notice, this list of conditions and the following disclaimer.
  10:  * 2. Redistributions in binary form must reproduce the above copyright
  11:  *    notice, this list of conditions and the following disclaimer in the
  12:  *    documentation and/or other materials provided with the distribution.
  13:  * 3. All advertising materials mentioning features or use of this software
  14:  *    must display the following acknowledgement:
  15:  *	This product includes software developed by the University of
  16:  *	California, Berkeley and its contributors.
  17:  * 4. Neither the name of the University nor the names of its contributors
  18:  *    may be used to endorse or promote products derived from this software
  19:  *    without specific prior written permission.
  20:  *
  21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31:  * SUCH DAMAGE.
  32:  */
  33: 
  34: #if !defined(lint) && defined(DOSCCS)
  35: static char copyright[] =
  36: "@(#) Copyright (c) 1993\n\
  37: 	The Regents of the University of California.  All rights reserved.\n";
  38: 
  39: static char sccsid[] = "@(#)uname.c	8.1.1 (2.11BSD GTE) 2/4/95";
  40: #endif /* not lint */
  41: 
  42: #include <sys/param.h>
  43: #include <sys/sysctl.h>
  44: 
  45: #include <stdio.h>
  46: 
  47: extern  int optind;
  48: 
  49: void usage();
  50: 
  51: int
  52: main(argc, argv)
  53:     int argc;
  54:     char *argv[];
  55: {
  56: #define MFLAG   0x01
  57: #define NFLAG   0x02
  58: #define RFLAG   0x04
  59: #define SFLAG   0x08
  60: #define VFLAG   0x10
  61:     register u_int flags;
  62:     int ch, mib[2];
  63:     size_t len, tlen;
  64:     register char *p, *prefix;
  65:     char buf[1024];
  66: 
  67:     flags = 0;
  68:     while ((ch = getopt(argc, argv, "amnrsv")) != EOF)
  69:         switch(ch) {
  70:         case 'a':
  71:             flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG);
  72:             break;
  73:         case 'm':
  74:             flags |= MFLAG;
  75:             break;
  76:         case 'n':
  77:             flags |= NFLAG;
  78:             break;
  79:         case 'r':
  80:             flags |= RFLAG;
  81:             break;
  82:         case 's':
  83:             flags |= SFLAG;
  84:             break;
  85:         case 'v':
  86:             flags |= VFLAG;
  87:             break;
  88:         case '?':
  89:         default:
  90:             usage();
  91:         }
  92: 
  93:     argc -= optind;
  94:     argv += optind;
  95: 
  96:     if (argc)
  97:         usage();
  98: 
  99:     if (!flags)
 100:         flags |= SFLAG;
 101: 
 102:     prefix = "";
 103: 
 104:     if (flags & SFLAG) {
 105:         mib[0] = CTL_KERN;
 106:         mib[1] = KERN_OSTYPE;
 107:         len = sizeof(buf);
 108:         if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
 109:             err(1, "sysctl");
 110:         (void)printf("%s%.*s", prefix, len, buf);
 111:         prefix = " ";
 112:     }
 113:     if (flags & NFLAG) {
 114:         mib[0] = CTL_KERN;
 115:         mib[1] = KERN_HOSTNAME;
 116:         len = sizeof(buf);
 117:         if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
 118:             err(1, "sysctl");
 119:         (void)printf("%s%.*s", prefix, len, buf);
 120:         prefix = " ";
 121:     }
 122:     if (flags & RFLAG) {
 123:         mib[0] = CTL_KERN;
 124:         mib[1] = KERN_OSRELEASE;
 125:         len = sizeof(buf);
 126:         if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
 127:             err(1, "sysctl");
 128:         (void)printf("%s%.*s", prefix, len, buf);
 129:         prefix = " ";
 130:     }
 131:     if (flags & VFLAG) {
 132:         mib[0] = CTL_KERN;
 133:         mib[1] = KERN_VERSION;
 134:         len = sizeof(buf);
 135:         if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
 136:             err(1, "sysctl");
 137:         for (p = buf, tlen = len; tlen--; ++p)
 138:             if (*p == '\n' || *p == '\t')
 139:                 *p = ' ';
 140:         (void)printf("%s%.*s", prefix, len, buf);
 141:         prefix = " ";
 142:     }
 143:     if (flags & MFLAG) {
 144:         mib[0] = CTL_HW;
 145:         mib[1] = HW_MACHINE;
 146:         len = sizeof(buf);
 147:         if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
 148:             err(1, "sysctl");
 149:         (void)printf("%s%.*s", prefix, len, buf);
 150:         prefix = " ";
 151:     }
 152:     (void)printf("\n");
 153:     exit (0);
 154: }
 155: 
 156: void
 157: usage()
 158: {
 159:     (void)fprintf(stderr, "usage: uname [-amnrsv]\n");
 160:     exit(1);
 161: }

Defined functions

main defined in line 51; never used
usage defined in line 156; used 3 times

Defined variables

copyright defined in line 35; never used
sccsid defined in line 39; never used

Defined macros

MFLAG defined in line 56; used 3 times
NFLAG defined in line 57; used 3 times
RFLAG defined in line 58; used 3 times
SFLAG defined in line 59; used 4 times
VFLAG defined in line 60; used 3 times
Last modified: 1995-02-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1325
Valid CSS Valid XHTML 1.0 Strict