[BACK]Return to uname.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / bin / uname

Annotation of prex-old/usr/bin/uname/uname.c, Revision 1.1

1.1     ! nbrk        1: /*
        !             2:  * Copyright (c) 2006-2007, Kohsuke Ohtani
        !             3:  * 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. Neither the name of the author nor the names of any co-contributors
        !            14:  *    may be used to endorse or promote products derived from this software
        !            15:  *    without specific prior written permission.
        !            16:  *
        !            17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            27:  * SUCH DAMAGE.
        !            28:  */
        !            29:
        !            30: #include <sys/utsname.h>
        !            31:
        !            32: #include <string.h>
        !            33: #include <unistd.h>
        !            34: #include <stdio.h>
        !            35: #include <stdlib.h>
        !            36: #include <errno.h>
        !            37: #include <stdio.h>
        !            38:
        !            39: #ifdef CMDBOX
        !            40: #define main(argc, argv)       uname_main(argc, argv)
        !            41: #endif
        !            42:
        !            43: #define        MFLAG   0x01
        !            44: #define        NFLAG   0x02
        !            45: #define        RFLAG   0x04
        !            46: #define        SFLAG   0x08
        !            47: #define        VFLAG   0x10
        !            48:
        !            49: static void
        !            50: usage(void)
        !            51: {
        !            52:        fprintf(stderr, "usage: uname [-amnpsrv]\n");
        !            53:        exit(1);
        !            54: }
        !            55:
        !            56: int
        !            57: main(int argc, char *argv[])
        !            58: {
        !            59:        u_int flags;
        !            60:        int ch;
        !            61:        struct utsname uts;
        !            62:
        !            63:        flags = 0;
        !            64:        while ((ch = getopt(argc, argv, "amnrsvp")) != EOF) {
        !            65:                switch(ch) {
        !            66:                case 'a':
        !            67:                        flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG);
        !            68:                        break;
        !            69:                case 'm':
        !            70:                        flags |= MFLAG;
        !            71:                        break;
        !            72:                case 'n':
        !            73:                        flags |= NFLAG;
        !            74:                        break;
        !            75:                case 'r':
        !            76:                        flags |= RFLAG;
        !            77:                        break;
        !            78:                case 's':
        !            79:                        flags |= SFLAG;
        !            80:                        break;
        !            81:                case 'v':
        !            82:                        flags |= VFLAG;
        !            83:                        break;
        !            84:                case '?':
        !            85:                default:
        !            86:                        usage();
        !            87:                }
        !            88:        }
        !            89:        argc -= optind;
        !            90:        argv += optind;
        !            91:
        !            92:        if (argc)
        !            93:                usage();
        !            94:
        !            95:        if (!flags)
        !            96:                flags |= SFLAG;
        !            97:
        !            98:        uname(&uts);
        !            99:
        !           100:        if (flags & SFLAG)
        !           101:                printf("%s ", uts.sysname);
        !           102:
        !           103:        if (flags & RFLAG)
        !           104:                printf("%s ", uts.release);
        !           105:
        !           106:        if (flags & VFLAG)
        !           107:                printf("%s ", uts.version);
        !           108:
        !           109:        if (flags & MFLAG)
        !           110:                printf("%s ", uts.machine);
        !           111:
        !           112:        if (flags & NFLAG)
        !           113:                printf("%s", uts.nodename);
        !           114:
        !           115:        putchar('\n');
        !           116:        exit(0);
        !           117: }

CVSweb