#ifndef __sun__ #include #endif #include #include #include #ifdef __APPLE__ #define u_int unsigned int #endif #define MFLAG 0x01 #define NFLAG 0x02 #define PFLAG 0x04 #define RFLAG 0x08 #define SFLAG 0x10 #define VFLAG 0x20 #define IFLAG 0x40 #define UFLAG 0x80 static void print_uname(u_int); static void usage(void); static const char *sysname = "@OPSYS@"; static const char *arch = "@ARCH@"; static const char *platform = "@PLATFORM@"; static const char *release = "@RELEASE@"; static const char *uservers = "@USERVER@"; static const char *ident = "GENERIC"; static const char *version = "@OPSYS@ @RELEASE@ #0 Sat Jul 29 09:00:00 CDT 2017 root@octavia.unreal.systems:/usr/obj/usr/src/sys/GENERIC"; static const char *hostname = "octavia.unreal.systems"; static int space; int main(int argc, char *argv[]) { u_int flags; int ch; flags = 0; while ((ch = getopt(argc, argv, "aimnoprsUv")) != -1) switch(ch) { case 'a': flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG); break; case 'i': flags |= IFLAG; break; case 'm': flags |= MFLAG; break; case 'n': flags |= NFLAG; break; case 'p': flags |= PFLAG; break; case 'r': flags |= RFLAG; break; case 's': case 'o': flags |= SFLAG; break; case 'U': flags |= UFLAG; break; case 'v': flags |= VFLAG; break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc) usage(); if (!flags) flags |= SFLAG; print_uname(flags); exit(0); } #define PRINT_FLAG(flags,flag,var) \ if ((flags & flag) == flag) { \ if (space) \ printf(" "); \ else \ space++; \ printf("%s", var); \ } static void print_uname(u_int flags) { PRINT_FLAG(flags, SFLAG, sysname); PRINT_FLAG(flags, NFLAG, hostname); PRINT_FLAG(flags, RFLAG, release); PRINT_FLAG(flags, VFLAG, version); PRINT_FLAG(flags, MFLAG, platform); PRINT_FLAG(flags, PFLAG, arch); PRINT_FLAG(flags, IFLAG, ident); PRINT_FLAG(flags, UFLAG, uservers); printf("\n"); } static void usage(void) { fprintf(stderr, "usage: uname [-aimnoprsUv]\n"); exit(1); }