I am trying to add android support.

This commit is contained in:
TheDarkBug 2021-01-19 19:37:28 +01:00
parent e89ac12eef
commit f12c1be5fe

31
main.c
View file

@ -2,8 +2,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef __linux__
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#elif __ANDROID__
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#elif _WIN32
#endif
// COLORS // COLORS
#define NORMAL "\x1b[0m" #define NORMAL "\x1b[0m"
#define BOLD "\x1b[1m" #define BOLD "\x1b[1m"
@ -20,24 +27,36 @@ void pkgman();
int main() { int main() {
// init variables and other useful things // init variables and other useful things
char user[32], host[253], shell[16]; char user[32], host[253], shell[64], version_name[64];
// get user and host names
#ifdef __linux__
struct utsname sys_var; struct utsname sys_var;
struct sysinfo sys; struct sysinfo sys;
// get user and host names
snprintf(user, 32, "%s", getenv("USER")); snprintf(user, 32, "%s", getenv("USER"));
gethostname(host, 253); gethostname(host, 253);
snprintf(shell, 16, "%s", getenv("SHELL")); snprintf(shell, 16, "%s", getenv("SHELL"));
memmove(&shell[0], &shell[5], 16); memmove(&shell[0], &shell[5], 16);
if (uname(&sys_var) == -1) printf("Ah sh-t, an error\n");
if (sysinfo(&sys) == -1) printf("Ah sh-t, an error\n");
char version_name[64];
FILE *fos_rel = popen("lsb_release -a | grep Description", "r"); FILE *fos_rel = popen("lsb_release -a | grep Description", "r");
fscanf(fos_rel,"%[^\n]", version_name); fscanf(fos_rel,"%[^\n]", version_name);
fclose(fos_rel); fclose(fos_rel);
memmove(&version_name[0], &version_name[12], 64); memmove(&version_name[0], &version_name[12], 64);
#elif __ANDROID__
FILE *fwhoami = popen("whoami", "r");
fscanf(fwhoami,"%[^\n]", user);
fclose(fwhoami);
FILE *fos_rel = popen("getprop ro.system.build.version.release", "r");
fscanf(fos_rel,"%[^\n]", version_name);
fclose(fos_rel);
snprintf(shell, 16, "%s", getenv("SHELL"));
memmove(&shell[0], &shell[36], 64);
#endif
if (uname(&sys_var) == -1) printf("Ah sh-t, an error\n");
if (sysinfo(&sys) == -1) printf("Ah sh-t, an error\n");
char cpu_model[128]; char cpu_model[128];
FILE *fcpu = popen("lscpu | grep 'Model name:'", "r"); FILE *fcpu = popen("lscpu | grep 'Model name:'", "r");