diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-04-26 00:54:48 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-04-26 00:54:58 -0400 |
commit | 2c8c1166d81a5c0fe6f335742ee24319ce60bfa8 (patch) | |
tree | c58e738644f9595fae67e2ade0ecec35f8b7eca4 /x86.c | |
parent | e71c07b9d5cc1236ca08536ae052faa5fc6b9096 (diff) | |
download | whatami-2c8c1166d81a5c0fe6f335742ee24319ce60bfa8.tar.gz |
Use static storage
* Almost everything returned by the system is immutable
* Fixed block_device array initialization and alphabetical sorting
* Free memory where possible
Diffstat (limited to 'x86.c')
-rw-r--r-- | x86.c | 20 |
1 files changed, 5 insertions, 15 deletions
@@ -37,26 +37,21 @@ int is_cpu_virtual() { char *get_sys_product() { union regs_t reg; - char *vendor; + static char vendor[255] = {0}; - vendor = NULL; if (is_cpu_virtual()) { - vendor = calloc(255, sizeof(*vendor)); - if (!vendor) { - return NULL; - } CPUID(0x40000000, ®); strncat(vendor, (char *) ®.bytes[1], sizeof(reg.bytes)); rstrip(vendor); } #if defined(__linux__) if (!vendor || !strlen(vendor)) { - vendor = get_sys_dmi_product(); + strcpy(vendor, get_sys_dmi_product()); rstrip(vendor); } #elif defined(__APPLE__) if (!vendor || !strlen(vendor)) { - vendor = get_sys_product_darwin(); + strcpy(vendor, get_sys_product_darwin()); rstrip(vendor); } #endif @@ -89,13 +84,9 @@ unsigned int get_cpu_count() { char *get_cpu_manufacturer() { union regs_t reg; - char *manufacturer; + static char manufacturer[255] = {0}; CPUID(0, ®); - manufacturer = calloc(sizeof(reg.bytes), sizeof(*reg.bytes)); - if (!manufacturer) { - return NULL; - } strncat(manufacturer, (char *) ®.bytes[1], 4); strncat(manufacturer, (char *) ®.bytes[3], 4); strncat(manufacturer, (char *) ®.bytes[2], 4); @@ -104,9 +95,8 @@ char *get_cpu_manufacturer() { char *get_cpu_vendor() { union regs_t reg; - char *vendor; + static char vendor[255] = {0}; - vendor = calloc(sizeof(reg.bytes) * 3, sizeof(*reg.bytes)); for (unsigned int leaf = 2; leaf < 5; leaf++) { CPUID(0x80000000 + leaf, ®); strncat(vendor, (char *) reg.bytes, sizeof(reg.bytes)); |