Compare commits

..

No commits in common. "9bddfa7a68c541d1581fee169bd8d6a835798f00" and "322ee8417a5c7337f7a4655d2be452bca0c0c107" have entirely different histories.

2 changed files with 16 additions and 25 deletions

View File

@ -1,8 +1,8 @@
#include "defs.h" #include "defs.h"
#define MAX_USERNAME_LENGTH 128 const int max_username_length = 128;
#define MAX_HOSTNAME_LENGTH 128 const int max_hostname_length = 128;
#define MAX_UPTIME_LENGTH 40 const int max_uptime_length = 40;
struct art_entry arts[] = { struct art_entry arts[] = {
{ {

View File

@ -5,9 +5,8 @@
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <sysinfoapi.h> #include <wdm.h>
#include <winsock.h> #include <winsock.h>
#include <Lm.h>
#include <winbase.h> #include <winbase.h>
#else #else
#include <sys/utsname.h> #include <sys/utsname.h>
@ -28,13 +27,8 @@ void die(int code, char *fmt, ...)
void getuptime(char *buffer, int max_length) void getuptime(char *buffer, int max_length)
{ {
#ifdef _WIN32
#define uptime.tv_sec uptime_seconds
long long uptime_seconds = GetTickCount64() / 1000;
#else
struct timespec uptime; struct timespec uptime;
clock_gettime(CLOCK_BOOTTIME, &uptime); clock_gettime(CLOCK_BOOTTIME, &uptime);
#endif /* _WIN32 */
int days = uptime.tv_sec / 86400; int days = uptime.tv_sec / 86400;
int hours = uptime.tv_sec / 3600 % 24; int hours = uptime.tv_sec / 3600 % 24;
int minutes = uptime.tv_sec / 60 % 60; int minutes = uptime.tv_sec / 60 % 60;
@ -49,9 +43,6 @@ void getuptime(char *buffer, int max_length)
else else
snprintf(buffer, max_length, "Up %d days, %d hours, %d minutes", days, hours, minutes); snprintf(buffer, max_length, "Up %d days, %d hours, %d minutes", days, hours, minutes);
} }
#ifdef _WIN32
#undef uptime.tv_sec
#endif /* _WIN32 */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -70,29 +61,29 @@ int main(int argc, char **argv)
art = arts[0].art; art = arts[0].art;
} }
char hostname[MAX_HOSTNAME_LENGTH]; char hostname[max_hostname_length];
char username[MAX_USERNAME_LENGTH]; char username[max_username_length];
char uptime[MAX_UPTIME_LENGTH]; char uptime[max_uptime_length];
#ifdef _WIN32 #ifdef _WIN32
SERVER_INFO_101 host_info; RTL_OSVERSIONINFOW version_buffer = {.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW)};
NetServerGetInfo(NULL, 101, &host_info); RtlGetVersion(&version_buffer);
GetUserNameA(username, MAX_USERNAME_LENGTH); GetUserNameA(username, max_username_length);
#else #else
struct utsname uname_buf; struct utsname uname_buf;
getlogin_r(username, MAX_USERNAME_LENGTH); getlogin_r(username, max_username_length);
uname(&uname_buf); uname(&uname_buf);
#endif /* _WIN32 */ #endif
gethostname(hostname, MAX_HOSTNAME_LENGTH); gethostname(hostname, max_hostname_length);
getuptime(uptime, MAX_UPTIME_LENGTH); getuptime(uptime, max_uptime_length);
printf("%s %s@%s\n", art[0], username, hostname); printf("%s %s@%s\n", art[0], username, hostname);
printf("%s --\n", art[1]); printf("%s --\n", art[1]);
#ifdef _WIN32 #ifdef _WIN32
printf("%s NT %d.%d\n", art[2], host_info.sv101_version_major & MAJOR_VERSION_MASK, host_info.sv101_version_minor); printf("%s NT %u.%u %s\n", art[2], version_buffer.dwMajorVersion, version_buffer.dwMinorVersion, version_buffer.szCSDVersion);
#else #else
printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release); printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release);
#endif /* _WIN32 */ #endif
printf("%s %s\n", art[3], uptime); printf("%s %s\n", art[3], uptime);
return 0; return 0;
} }