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