1 | /* |
---|
2 | * Copyright (c) 1992-1998 Michael A. Cooper. |
---|
3 | * This software may be freely used and distributed provided it is not |
---|
4 | * sold for profit or used in part or in whole for commercial gain |
---|
5 | * without prior written agreement, and the author is credited |
---|
6 | * appropriately. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef lint |
---|
10 | static char *RCSid = "$Revision: 1.1.1.3 $"; |
---|
11 | #endif |
---|
12 | |
---|
13 | /* |
---|
14 | * Get OS version information |
---|
15 | */ |
---|
16 | |
---|
17 | #include "defs.h" |
---|
18 | |
---|
19 | /* |
---|
20 | * Get OS version number using uname() |
---|
21 | */ |
---|
22 | extern char *GetOSVerUname() |
---|
23 | { |
---|
24 | static char Buff[64]; |
---|
25 | #if defined(HAVE_UNAME) |
---|
26 | struct utsname un; |
---|
27 | |
---|
28 | if (uname(&un) >= 0) { |
---|
29 | /* |
---|
30 | * Vendors don't all do the same thing for storing |
---|
31 | * version numbers via uname(). |
---|
32 | */ |
---|
33 | #if defined(UNAME_REL_VER_COMB) |
---|
34 | (void) snprintf(Buff, sizeof(Buff), "%s.%s", un.version, un.release); |
---|
35 | #else |
---|
36 | (void) snprintf(Buff, sizeof(Buff), "%s", un.release); |
---|
37 | #endif /* UNAME_REL_VER_COMB */ |
---|
38 | } |
---|
39 | #endif /* HAVE_UNAME */ |
---|
40 | |
---|
41 | return( (Buff[0]) ? Buff : (char *) NULL ); |
---|
42 | } |
---|
43 | |
---|
44 | /* |
---|
45 | * Get OS version by reading an a specific argument out of |
---|
46 | * the kernel version string. |
---|
47 | */ |
---|
48 | extern char *GetOSVerKernVer() |
---|
49 | { |
---|
50 | static char Buff[256]; |
---|
51 | #if defined(OSVERS_FROM_KERNVER) |
---|
52 | register char *cp; |
---|
53 | register int i; |
---|
54 | |
---|
55 | if (!(cp = GetKernVer())) |
---|
56 | return((char *) NULL); |
---|
57 | |
---|
58 | (void) strcpy(Buff, cp); |
---|
59 | for (cp = strtok(Buff, " "), i = 0; cp && i != OSVERS_FROM_KERNVER-1; |
---|
60 | cp = strtok((char *)NULL, " "), ++i); |
---|
61 | (void) strcpy(Buff, cp); |
---|
62 | if ((cp = strchr(Buff, ':')) != NULL) |
---|
63 | *cp = C_NULL; |
---|
64 | #endif /* OSVERS_FROM_KERNVER */ |
---|
65 | |
---|
66 | return( (Buff[0]) ? Buff : (char *) NULL ); |
---|
67 | } |
---|
68 | |
---|
69 | /* |
---|
70 | * Get OS version using sysinfo() system call. |
---|
71 | */ |
---|
72 | extern char *GetOSVerSysinfo() |
---|
73 | { |
---|
74 | static char Buff[128]; |
---|
75 | |
---|
76 | #if defined(HAVE_SYSINFO) |
---|
77 | if (Buff[0]) |
---|
78 | return(Buff); |
---|
79 | |
---|
80 | if (sysinfo(SI_RELEASE, Buff, sizeof(Buff)) < 0) |
---|
81 | return((char *) NULL); |
---|
82 | #endif /* HAVE_SYSINFO */ |
---|
83 | |
---|
84 | return( (Buff[0]) ? Buff : (char *) NULL ); |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * Use predefined OS_NAME. |
---|
89 | */ |
---|
90 | extern char *GetOSVerDef() |
---|
91 | { |
---|
92 | #if defined(OS_VERSION) |
---|
93 | return(OS_VERSION); |
---|
94 | #else |
---|
95 | return((char *) NULL); |
---|
96 | #endif /* OS_VERSION */ |
---|
97 | } |
---|
98 | |
---|
99 | /* |
---|
100 | * Get Operating System version |
---|
101 | */ |
---|
102 | extern char *GetOSVer() |
---|
103 | { |
---|
104 | extern PSI_t GetOSVerPSI[]; |
---|
105 | static char *Str; |
---|
106 | register char *cp; |
---|
107 | |
---|
108 | if (Str) |
---|
109 | return(Str); |
---|
110 | |
---|
111 | if (Str = PSIquery(GetOSVerPSI)) |
---|
112 | /* |
---|
113 | * Zap "*-PL*". |
---|
114 | */ |
---|
115 | if (*Str && ((cp = strrchr(Str, '-')) != NULL) && |
---|
116 | (strncmp(cp, "-PL", 3) == 0)) |
---|
117 | *cp = C_NULL; |
---|
118 | |
---|
119 | return(Str); |
---|
120 | } |
---|