1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*----------------------------------------------------------------------------*
LinuxInfo_common.c - common functions
by Alex Buell
September 1998
-----------------------------------------------------------------------------
Derived from Vince Weaver's Linux Logo 2.10
-----------------------------------------------------------------------------
HISTORY
1.0.1 - Initial Development
1.0.2 - Modifications to enable libc5 & glibc2 compatiblity.
1.0.3 - Bug fix for glibc-2.0.x (not glibc-2.0.9x - works fine).
1.0.4 - Gave up in disgust and used a clever hack :o) Sit back and
admire the elegance of this code!
-----------------------------------------------------------------------------*/
#include "linuxinfo.h"
void GetOperatingSystemInfo(struct os_stat *os)
{
#ifndef system_unknown
struct utsname buf;
uname(&buf);
strcpy(os->os_hostname, buf.nodename);
strcpy(os->os_name, buf.sysname);
strcpy(os->os_version, buf.release);
strcpy(os->os_revision, buf.version);
#else
strcpy(os->os_hostname, "Unknown");
strcpy(os->os_name, "Unknown");
strcpy(os->os_version, "Unknown");
strcpy(os->os_revision, "Unknown");
#endif /* system_unknown */
}
/* Really neat hack to detect all libraries known on Linux */
#ifndef system_unknown
asm (".weak gnu_get_libc_version");
asm (".weak __libc_version");
asm (".weak __linux_C_lib_version");
extern char *gnu_get_libc_version (void);
extern char *__linux_C_lib_version;
extern char __libc_version [];
#endif /* only define if on a Linux system :o) */
void GetSystemLibcInfo(struct lib_stat *lib)
{
int libc_major = 0, libc_minor = 0, libc_teeny = 0;
char *ptr;
/* initialise to unknown */
strcpy(lib->lib_version, "Unknown");
#ifndef system_unknown
if (gnu_get_libc_version != 0)
{
ptr = gnu_get_libc_version();
}
else if (&__libc_version != 0)
{
ptr = __libc_version;
}
else
ptr = __linux_C_lib_version;
while (!isdigit (*ptr))
ptr++;
sscanf (ptr, "%d.%d.%d", &libc_major, &libc_minor, &libc_teeny);
sprintf(lib->lib_version, "%d.%d.%d", libc_major, libc_minor, libc_teeny);
#endif /* system_unknown */
}
char *GetStringFromFile(FILE *infile, char *str)
{
int ch, i = 0;
char temp[BUFSIZ];
strcpy(temp, "");
while ((ch = fgetc(infile)) == ' ');
while ((ch != '\n') && (ch != EOF))
{
temp[i] = ch;
i++;
ch = fgetc(infile);
}
if (ch == EOF)
return NULL;
temp[i] = '\0';
strcpy(str, temp);
return(str);
}
int splitstring(char *first_string, char *second_string)
{
char *p;
p = strchr(first_string, ':');
if (!p)
return 0;
*(p-1) = '\0', p++;
while (isspace(*p)) p++;
strcpy(second_string, p);
}
|