[bugfix] removed double definition of structs
This commit is contained in:
parent
b0cc2d9d5d
commit
fcf5680e72
45
source/lib.c
45
source/lib.c
@ -13,6 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "lib.h"
|
||||
|
||||
@ -40,11 +41,6 @@ void device_os_version();
|
||||
void device_hostname();
|
||||
void device_model();
|
||||
|
||||
cpu_s *u_cpu ;
|
||||
ram_s *u_ram ;
|
||||
disk_s *u_disk ;
|
||||
device_s *u_device ;
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <sys/sysinfo.h>
|
||||
@ -183,48 +179,51 @@ void device_mdoel() {
|
||||
|
||||
void cpu_name() {
|
||||
|
||||
char *name;
|
||||
char *name = NULL;
|
||||
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");
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0){
|
||||
|
||||
perror("error in assigning the size for the cpu name variable\n");
|
||||
return;
|
||||
}
|
||||
|
||||
name = malloc(len);
|
||||
|
||||
if (name == NULL) {
|
||||
perror("malloc failed");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
u_cpu->name = name;
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_threads() {
|
||||
|
||||
int count;
|
||||
size_t len = sizeof(count);
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0){
|
||||
perror("error in retrieving the cpu threads count\n");
|
||||
return;
|
||||
}
|
||||
|
||||
u_cpu->threads = count;
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_frequency() {
|
||||
uint64_t freq = 0;
|
||||
size_t size = sizeof(freq);
|
||||
// assigning a value of 0, value not available on macos
|
||||
u_cpu->frequency = 0;
|
||||
|
||||
if (sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0) < 0)
|
||||
{
|
||||
perror("sysctl");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_temperature() {
|
||||
// assigning a value of 0, value not available on macos
|
||||
u_cpu->temperature = 0;
|
||||
}
|
||||
|
||||
@ -248,13 +247,11 @@ void mem_av_size() {
|
||||
|
||||
void get_total() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void get_usage() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void device_hostname(){
|
||||
@ -306,13 +303,12 @@ void device_model(){
|
||||
}
|
||||
|
||||
u_device->name = model_name;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void device_os_version() {
|
||||
|
||||
char *os_version;
|
||||
char *os_version = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
||||
@ -327,9 +323,6 @@ void device_os_version() {
|
||||
}
|
||||
|
||||
u_device->os_version = os_version;
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -11,24 +11,27 @@ device_s *u_device;
|
||||
|
||||
void init() {
|
||||
|
||||
u_cpu = malloc( sizeof(cpu_s) );
|
||||
u_ram = malloc(sizeof(ram_s));
|
||||
u_disk = malloc(sizeof(disk_s));
|
||||
u_device = malloc(sizeof(device_s));
|
||||
|
||||
cpu_name();
|
||||
cpu_frequency();
|
||||
cpu_threads();
|
||||
cpu_temperature();
|
||||
|
||||
mem_size();
|
||||
mem_av_size();
|
||||
|
||||
get_total();
|
||||
get_usage();
|
||||
|
||||
device_os_version();
|
||||
device_model();
|
||||
device_up_time();
|
||||
device_model();
|
||||
|
||||
u_cpu = malloc(sizeof(cpu_s));
|
||||
u_ram = malloc(sizeof(disk_s));
|
||||
u_disk = malloc(sizeof(disk_s));
|
||||
u_cpu = malloc(sizeof(device_s));
|
||||
|
||||
}
|
||||
|
||||
void end() {
|
||||
@ -44,8 +47,20 @@ int main() {
|
||||
|
||||
init();
|
||||
|
||||
printf("%d\n%s\n%s\n%d\n", u_cpu->temperature, u_cpu->frequency, u_cpu->name, u_cpu->threads);
|
||||
printf("%s\n%s\n%s\n%d", u_device->name, u_device->hostname, u_device->os_version, u_device->uptime);
|
||||
printf("temperature: %d\nfrequency: %s\nname: %s\nthreads: %d\n", u_cpu->temperature, u_cpu->frequency, u_cpu->name, u_cpu->threads);
|
||||
printf("total: %ld\navailable: %ld\n", u_ram->total, u_ram->available);
|
||||
printf("device name:%s\ndevice hostname:%s\nos version: %s\nuptime: %d\n", u_device->name, u_device->hostname, u_device->os_version, u_device->uptime);
|
||||
|
||||
while(1) {
|
||||
|
||||
char *input = malloc(sizeof(char *));
|
||||
|
||||
if(scanf("%s\n", input)) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
end();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -11,13 +11,13 @@ typedef struct {
|
||||
} cpu_s;
|
||||
|
||||
typedef struct {
|
||||
unsigned long total;
|
||||
unsigned long available;
|
||||
long int total;
|
||||
long int available;
|
||||
} ram_s;
|
||||
|
||||
typedef struct {
|
||||
long long size;
|
||||
short name;
|
||||
long size;
|
||||
char *name;
|
||||
} disk_s;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user