Annotation of coherent/b/bin/uname.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * uname.c
                      3:  * Print information about current COHERENT system.
                      4:  */
                      5: 
                      6: #include       <stdio.h>
                      7: #include       <fcntl.h>
                      8: #include       <sys/utsname.h>
                      9: #include       <string.h>
                     10: 
                     11: main(argc, argv)
                     12: int    argc;
                     13: char   *argv[];
                     14: {
                     15:        extern char     *optarg;
                     16:        extern int      optind;
                     17:        static int      snf = 0,        /* Default */
                     18:                        nnf = 0,
                     19:                        srf = 0, 
                     20:                        svf = 0, 
                     21:                        mhf = 0,
                     22:                        Snf = 0;
                     23:        char            *sname;
                     24:        int             c;
                     25:        struct utsname  tsname;
                     26: 
                     27:        while ((c = getopt(argc, argv, "snrvmaS:")) != EOF)
                     28:                switch (c) {
                     29:                case 's':       /* Print system name (default). */
                     30:                        snf = 1;
                     31:                        break;
                     32:                case 'n':       /* Print node name */
                     33:                        nnf = 1;
                     34:                        break;
                     35:                case 'r':       /* Print system release */
                     36:                        srf = 1;
                     37:                        break;
                     38:                case 'v':       /* Print system version */
                     39:                        svf = 1;
                     40:                        break;
                     41:                case 'm':       /* Print machine hardware name */
                     42:                        mhf = 1;
                     43:                        break;
                     44:                case 'a':       /* Print all above */
                     45:                        nnf = srf = svf = mhf = 1;
                     46:                        break;
                     47:                case 'S':       /* Change system name */
                     48:                        Snf = 1;
                     49:                        sname = optarg;                 
                     50:                        break;
                     51:                default:
                     52:                        usage();
                     53:                }
                     54:        if ((snf || nnf || srf || svf || mhf) && Snf)
                     55:                usage();
                     56:        if (Snf)
                     57:                changename(sname);
                     58:        else {
                     59:                int space;
                     60: 
                     61:                if (uname(&tsname) < 0) {
                     62:                        perror("uname");
                     63:                        exit(1);
                     64:                }
                     65:                space = 0;
                     66:                if (snf) {
                     67:                        printf("%.*s", SYS_NMLN, tsname.sysname);
                     68:                        space = 1;
                     69:                }
                     70:                if (nnf) {
                     71:                        if (space)
                     72:                                putchar(' ');
                     73:                        printf("%.*s", SYS_NMLN, tsname.nodename);
                     74:                        space = 1;
                     75:                }
                     76:                if (srf) {
                     77:                        if (space)
                     78:                                putchar(' ');
                     79:                        printf("%.*s", SYS_NMLN, tsname.release);
                     80:                        space = 1;
                     81:                }
                     82:                if (svf) {
                     83:                        if (space)
                     84:                                putchar(' ');
                     85:                        printf("%.*s", SYS_NMLN, tsname.version);
                     86:                        space = 1;
                     87:                }
                     88:                if (mhf) {
                     89:                        if (space)
                     90:                                putchar(' ');
                     91:                        printf("%.*s", SYS_NMLN, tsname.machine);
                     92:                }
                     93:                putchar('\n');
                     94:        }
                     95:        exit(0);
                     96: }
                     97: 
                     98: /*
                     99:  * Change system name.
                    100:  */
                    101: changename(sname)
                    102: char   *sname;
                    103: {
                    104:        char    newname[SYS_NMLN + 2];
                    105:        int     fd;
                    106:        char    *uucpname = "/etc/uucpname";
                    107: 
                    108:        if (strlen(sname) >= SYS_NMLN) {
                    109:                fprintf(stderr, "uname: name must be <= 8 characters.\n");
                    110:                exit(1);
                    111:        }
                    112:        strcpy(newname, sname);
                    113:        strcat(newname, "\n");
                    114:        if ((fd = open(uucpname, O_RDWR | O_TRUNC, 0644)) < 0) {
                    115:                perror("uname");
                    116:                exit(1);
                    117:        }
                    118:        if (write(fd, newname, strlen(newname)) != strlen(newname)) {
                    119:                perror("uname");
                    120:                exit(1);
                    121:        }
                    122: }
                    123: 
                    124: usage()
                    125: {
                    126:        printf("usage:\tuname [-snrvma]\n\tuname [-S system_name]\n");
                    127:        exit(1);
                    128: }
                    129: 
                    130: /* end of uname.c */

unix.superglobalmegacorp.com

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