merged every modular file into one lib.c
This commit is contained in:
parent
6927df5ec2
commit
9d64a6e3fd
@ -1,4 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
@ -112,4 +112,62 @@ void *cpu_i(void *a){
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#ifdef __gnu_linux__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long mem_size;
|
||||||
|
} ram;
|
||||||
|
|
||||||
|
unsigned long get_total(void);
|
||||||
|
unsigned long get_usage(void);
|
||||||
|
void *ram_i(void *a);
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long get_total(void){
|
||||||
|
|
||||||
|
struct sysinfo info;
|
||||||
|
|
||||||
|
if (sysinfo(&info) != 0) {
|
||||||
|
perror("sysinfo");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
long total_ram = info.totalram * info.mem_unit;
|
||||||
|
return total_ram;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long get_usage(void)
|
||||||
|
{
|
||||||
|
struct sysinfo info;
|
||||||
|
|
||||||
|
if (sysinfo(&info) != 0) {
|
||||||
|
perror("sysinfo");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
long total_ram = info.totalram * info.mem_unit;
|
||||||
|
long free_ram = info.freeram * info.mem_unit;
|
||||||
|
|
||||||
|
return total_ram - free_ram;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ram_i(void *a){
|
||||||
|
|
||||||
|
printf("thread is working");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,58 +0,0 @@
|
|||||||
#ifdef __gnu_linux__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned long mem_size;
|
|
||||||
} ram;
|
|
||||||
|
|
||||||
unsigned long get_total(void);
|
|
||||||
unsigned long get_usage(void);
|
|
||||||
void *ram_i(void *a);
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long get_total(void){
|
|
||||||
|
|
||||||
struct sysinfo info;
|
|
||||||
|
|
||||||
if (sysinfo(&info) != 0) {
|
|
||||||
perror("sysinfo");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
long total_ram = info.totalram * info.mem_unit;
|
|
||||||
return total_ram;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long get_usage(void)
|
|
||||||
{
|
|
||||||
struct sysinfo info;
|
|
||||||
|
|
||||||
if (sysinfo(&info) != 0) {
|
|
||||||
perror("sysinfo");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
long total_ram = info.totalram * info.mem_unit;
|
|
||||||
long free_ram = info.freeram * info.mem_unit;
|
|
||||||
|
|
||||||
return total_ram - free_ram;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *ram_i(void *a){
|
|
||||||
|
|
||||||
printf("thread is working");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include "cpu.h"
|
|
||||||
|
|
||||||
void* cpu_name();
|
|
||||||
void* cpu_thread_count();
|
|
||||||
|
|
||||||
cpu_s cpu;
|
|
||||||
|
|
||||||
void* cpu_name(){
|
|
||||||
|
|
||||||
char *name;
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0)
|
|
||||||
perror("errorn in assigning the size for the cpu name variable\n");
|
|
||||||
|
|
||||||
name = malloc(len);
|
|
||||||
|
|
||||||
if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){
|
|
||||||
perror("error in assigning the value to the cpu name variable\n");
|
|
||||||
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
cpu.name = name;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* cpu_threads(){
|
|
||||||
|
|
||||||
int count;
|
|
||||||
size_t len = sizeof(count);
|
|
||||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
|
||||||
perror("error in retrieving the cpu threads count\n");
|
|
||||||
|
|
||||||
cpu.threads = count;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* cpu_info(){
|
|
||||||
cpu_threads();
|
|
||||||
cpu_name();
|
|
||||||
|
|
||||||
printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <device.h>
|
|
||||||
|
|
||||||
device_s device_info;
|
|
||||||
|
|
||||||
void* device_name(){
|
|
||||||
|
|
||||||
char *name;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0)
|
|
||||||
perror("failed retrieving the hostname: \n");
|
|
||||||
|
|
||||||
name = malloc(size);
|
|
||||||
|
|
||||||
if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){
|
|
||||||
perror("failed retrieving the hostname: \n");
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
device_info.name = name;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void* device_model(){
|
|
||||||
|
|
||||||
char *model_name;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0)
|
|
||||||
perror("failed retrieving the hostname: \n");
|
|
||||||
|
|
||||||
model_name = malloc(size);
|
|
||||||
|
|
||||||
if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){
|
|
||||||
perror("failed retrieving the hostname: \n");
|
|
||||||
free(model_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
device_info.model = model_name;
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void* device_up_time(){
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* device_os_version(){
|
|
||||||
|
|
||||||
char *os_version;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
|
||||||
perror("failed retrieving the hostname: \n");
|
|
||||||
|
|
||||||
os_version = malloc(size);
|
|
||||||
|
|
||||||
if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){
|
|
||||||
perror("failed retrieving the os version: \n");
|
|
||||||
free(os_version);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
device_info.model = os_version;
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void* get_device_info(){
|
|
||||||
device_name();
|
|
||||||
device_model();
|
|
||||||
printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
#include "disk.h"
|
|
||||||
|
|
||||||
|
|
||||||
void* disk_size();
|
|
||||||
|
|
||||||
disk_s disk_info;
|
|
||||||
|
|
||||||
void* disk_size(){
|
|
||||||
|
|
||||||
struct statfs disk;
|
|
||||||
|
|
||||||
statfs("/", &disk);
|
|
||||||
|
|
||||||
disk_info.size = disk.f_bfree;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* get_disk_info(){
|
|
||||||
|
|
||||||
printf("free disk space: %llu\n", disk_info.size);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include "modules/cpu.h"
|
|
||||||
#include "modules/ram.h"
|
|
||||||
#include "modules/disk.h"
|
|
||||||
#include "modules/device.h"
|
|
||||||
#include <cjson/cJSON.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
|
|
||||||
cpu_s* cpu;
|
|
||||||
ram_s* ram;
|
|
||||||
disk_s* disk;
|
|
||||||
device_s* device;
|
|
||||||
|
|
||||||
} info;
|
|
||||||
|
|
||||||
|
|
||||||
cJSON convert_to_json(info info){
|
|
||||||
|
|
||||||
cJSON *root = cJSON_CreateObject();
|
|
||||||
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
|
||||||
cJSON_AddNumberToObject(root, "ram", info.ram->total);
|
|
||||||
cJSON_AddStringToObject(root, "disk", info.disk->name);
|
|
||||||
cJSON_AddStringToObject(root, "device", info.device->name);
|
|
||||||
|
|
||||||
return *root;
|
|
||||||
}
|
|
||||||
238
source/osx/lib.c
Normal file
238
source/osx/lib.c
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include "cpu.h"
|
||||||
|
|
||||||
|
void* cpu_name();
|
||||||
|
void* cpu_thread_count();
|
||||||
|
|
||||||
|
cpu_s cpu;
|
||||||
|
|
||||||
|
void* cpu_name(){
|
||||||
|
|
||||||
|
char *name;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0)
|
||||||
|
perror("errorn in assigning the size for the cpu name variable\n");
|
||||||
|
|
||||||
|
name = malloc(len);
|
||||||
|
|
||||||
|
if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){
|
||||||
|
perror("error in assigning the value to the cpu name variable\n");
|
||||||
|
|
||||||
|
free(name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.name = name;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cpu_threads(){
|
||||||
|
|
||||||
|
int count;
|
||||||
|
size_t len = sizeof(count);
|
||||||
|
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
||||||
|
perror("error in retrieving the cpu threads count\n");
|
||||||
|
|
||||||
|
cpu.threads = count;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cpu_info(){
|
||||||
|
cpu_threads();
|
||||||
|
cpu_name();
|
||||||
|
|
||||||
|
printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <device.h>
|
||||||
|
|
||||||
|
device_s device_info;
|
||||||
|
|
||||||
|
void* device_name(){
|
||||||
|
|
||||||
|
char *name;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0)
|
||||||
|
perror("failed retrieving the hostname: \n");
|
||||||
|
|
||||||
|
name = malloc(size);
|
||||||
|
|
||||||
|
if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){
|
||||||
|
perror("failed retrieving the hostname: \n");
|
||||||
|
free(name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
device_info.name = name;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* device_model(){
|
||||||
|
|
||||||
|
char *model_name;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0)
|
||||||
|
perror("failed retrieving the hostname: \n");
|
||||||
|
|
||||||
|
model_name = malloc(size);
|
||||||
|
|
||||||
|
if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){
|
||||||
|
perror("failed retrieving the hostname: \n");
|
||||||
|
free(model_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
device_info.model = model_name;
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void* device_up_time(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* device_os_version(){
|
||||||
|
|
||||||
|
char *os_version;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
||||||
|
perror("failed retrieving the hostname: \n");
|
||||||
|
|
||||||
|
os_version = malloc(size);
|
||||||
|
|
||||||
|
if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){
|
||||||
|
perror("failed retrieving the os version: \n");
|
||||||
|
free(os_version);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
device_info.model = os_version;
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void* get_device_info(){
|
||||||
|
device_name();
|
||||||
|
device_model();
|
||||||
|
printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "modules/cpu.h"
|
||||||
|
#include "modules/ram.h"
|
||||||
|
#include "modules/disk.h"
|
||||||
|
#include "modules/device.h"
|
||||||
|
#include <cjson/cJSON.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
cpu_s* cpu;
|
||||||
|
ram_s* ram;
|
||||||
|
disk_s* disk;
|
||||||
|
device_s* device;
|
||||||
|
|
||||||
|
} info;
|
||||||
|
|
||||||
|
|
||||||
|
cJSON convert_to_json(info info){
|
||||||
|
|
||||||
|
cJSON *root = cJSON_CreateObject();
|
||||||
|
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
||||||
|
cJSON_AddNumberToObject(root, "ram", info.ram->total);
|
||||||
|
cJSON_AddStringToObject(root, "disk", info.disk->name);
|
||||||
|
cJSON_AddStringToObject(root, "device", info.device->name);
|
||||||
|
|
||||||
|
return *root;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "ram.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
void size();
|
||||||
|
void av_size();
|
||||||
|
void* ram_i();
|
||||||
|
|
||||||
|
|
||||||
|
ram_s data;
|
||||||
|
|
||||||
|
#define D 1073741824
|
||||||
|
|
||||||
|
|
||||||
|
void size() {
|
||||||
|
int64_t size;
|
||||||
|
size_t len = sizeof(size);
|
||||||
|
if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0)
|
||||||
|
perror("error in retrieving the memory size");
|
||||||
|
|
||||||
|
data.total = size / D;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void av_size() {
|
||||||
|
int64_t size;
|
||||||
|
size_t len = sizeof(size);
|
||||||
|
if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0)
|
||||||
|
perror("error in retrieving the available memory size");
|
||||||
|
|
||||||
|
data.available = size / D;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ram_info() {
|
||||||
|
size();
|
||||||
|
av_size();
|
||||||
|
|
||||||
|
printf("available ram: %LF\n", data.available);
|
||||||
|
printf("total ram: %LF\n", data.total);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* ram_i(){
|
||||||
|
|
||||||
|
printf("thread is working");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,57 +0,0 @@
|
|||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "ram.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
|
|
||||||
void size();
|
|
||||||
void av_size();
|
|
||||||
void* ram_i();
|
|
||||||
|
|
||||||
|
|
||||||
ram_s data;
|
|
||||||
|
|
||||||
#define D 1073741824
|
|
||||||
|
|
||||||
|
|
||||||
void size() {
|
|
||||||
int64_t size;
|
|
||||||
size_t len = sizeof(size);
|
|
||||||
if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0)
|
|
||||||
perror("error in retrieving the memory size");
|
|
||||||
|
|
||||||
data.total = size / D;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void av_size() {
|
|
||||||
int64_t size;
|
|
||||||
size_t len = sizeof(size);
|
|
||||||
if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0)
|
|
||||||
perror("error in retrieving the available memory size");
|
|
||||||
|
|
||||||
data.available = size / D;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ram_info() {
|
|
||||||
size();
|
|
||||||
av_size();
|
|
||||||
|
|
||||||
printf("available ram: %LF\n", data.available);
|
|
||||||
printf("total ram: %LF\n", data.total);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* ram_i(){
|
|
||||||
|
|
||||||
printf("thread is working");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Reference in New Issue
Block a user