Host Info

The Fossil System Hostinfo module provides a unified, portable interface for querying detailed information about the host environment at runtime. It exposes structured access to operating system metadata, hardware characteristics, memory and storage usage, power and battery state, virtualization detection, environment variables, and system uptime. The C API is designed around simple, caller-owned structures with predictable behavior and no dynamic allocation, making it suitable for low-level diagnostics and tooling. The accompanying C++ wrapper offers a thin, header-only, value-returning interface that preserves ABI stability while enabling expressive and idiomatic access to host metadata.

HEADER REFERENCE #

#ifndef FOSSIL_SYS_HOSTINFO_H
#define FOSSIL_SYS_HOSTINFO_H

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

// System information structure
typedef struct {
    char os_name[128];
    char os_version[128];
    char kernel_version[128];
    char hostname[128];
    char username[128];
    char domain_name[128];
    char machine_type[128];
    char platform[128];
} fossil_sys_hostinfo_system_t;

// Architecture information structure
typedef struct {
    char architecture[128];
    char cpu[128];
    char cpu_cores[128];
    char cpu_threads[128];
    char cpu_frequency[128];
    char cpu_architecture[128];
} fossil_sys_hostinfo_architecture_t;

// Memory information structure
typedef struct {
    uint64_t total_memory;    // in bytes
    uint64_t free_memory;     // in bytes
    uint64_t used_memory;     // in bytes
    uint64_t available_memory;// in bytes
    uint64_t total_swap;      // in bytes
    uint64_t free_swap;       // in bytes
    uint64_t used_swap;       // in bytes
} fossil_sys_hostinfo_memory_t;

// Endianness information structure
typedef struct {
    int is_little_endian; // 1 if little-endian, 0 if big-endian
} fossil_sys_hostinfo_endianness_t;

/**
 * Power information structure
 */
typedef struct {
    int on_ac_power;         // 1 if on AC power, 0 otherwise
    int battery_present;     // 1 if battery is present, 0 otherwise
    int battery_charging;    // 1 if battery is charging, 0 otherwise
    int battery_percentage;  // Battery charge percentage (0-100), -1 if unknown
    int battery_seconds_left;// Estimated seconds left, -1 if unknown
} fossil_sys_hostinfo_power_t;

/**
 * CPU information structure
 */
typedef struct {
    char model[128];
    char vendor[128];
    int cores;
    int threads;
    float frequency_ghz;
    char features[256];
} fossil_sys_hostinfo_cpu_t;

/**
 * GPU information structure
 */
typedef struct {
    char name[128];
    char vendor[128];
    char driver_version[64];
    uint64_t memory_total;
    uint64_t memory_free;
} fossil_sys_hostinfo_gpu_t;

/**
 * Storage information structure
 */
typedef struct {
    char device_name[128];
    char mount_point[128];
    uint64_t total_space;    // in bytes
    uint64_t free_space;     // in bytes
    uint64_t used_space;     // in bytes
    char filesystem_type[64];
} fossil_sys_hostinfo_storage_t;

/**
 * Environment information structure
 */
typedef struct {
    char shell[128];
    char home_dir[256];
    char lang[64];
    char path[1024];
    char _term[64];
    char user[128];
} fossil_sys_hostinfo_environment_t;

typedef struct {
    int is_virtual_machine;     // 1 if VM detected
    int is_container;           // 1 if running in container
    char hypervisor[128];       // e.g. "KVM", "VMware", "Hyper-V"
    char container_type[64];    // e.g. "docker", "podman", "lxc"
} fossil_sys_hostinfo_virtualization_t;

typedef struct {
    uint64_t uptime_seconds;
    uint64_t boot_time_epoch; // seconds since Unix epoch, 0 if unknown
} fossil_sys_hostinfo_uptime_t;

/**
 * @brief Retrieves the system uptime information.
 *
 * This function fills the provided fossil_sys_hostinfo_uptime_t structure
 * with the current uptime details of the host system. The uptime typically
 * represents the amount of time (in seconds or other units) that the system
 * has been running since its last boot.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_uptime_t structure that
 *                  will be populated with the uptime information.
 *
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_uptime(fossil_sys_hostinfo_uptime_t *info);

/**
 * @brief Retrieves virtualization information about the host system.
 *
 * This function populates the given fossil_sys_hostinfo_virtualization_t
 * structure with details regarding the virtualization environment, if any,
 * in which the host system is running. This may include information such as
 * the type of hypervisor detected or whether the system is running on bare metal.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_virtualization_t structure
 *                  that will be filled with virtualization details.
 *
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_virtualization(
    fossil_sys_hostinfo_virtualization_t *info
);

/**
 * @brief Retrieves storage information about the host system.
 *
 * This function fills the provided fossil_sys_hostinfo_storage_t structure
 * with details about the system's storage device, such as device name,
 * mount point, total space, free space, used space, and filesystem type.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_storage_t structure that
 *                  will be populated with storage information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_storage(fossil_sys_hostinfo_storage_t *info);

/**
 * @brief Retrieves environment information for the current user session.
 *
 * This function populates the fossil_sys_hostinfo_environment_t structure
 * with details such as the user's shell, home directory, language, PATH,
 * terminal type, and username.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_environment_t structure
 *                  that will be filled with environment information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_environment(fossil_sys_hostinfo_environment_t *info);

/**
 * @brief Retrieves CPU information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_cpu_t structure with details
 * about the CPU, including model, vendor, number of cores, threads,
 * frequency, and supported features.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_cpu_t structure that
 *                  will be populated with CPU information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_cpu(fossil_sys_hostinfo_cpu_t *info);

/**
 * @brief Retrieves GPU information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_gpu_t structure with details
 * about the GPU, such as name, vendor, driver version, and memory statistics.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_gpu_t structure that
 *                  will be populated with GPU information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_gpu(fossil_sys_hostinfo_gpu_t *info);

/**
 * @brief Retrieves power information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_power_t structure with details
 * about the system's power state, including AC power status, battery presence,
 * charging state, battery percentage, and estimated time remaining.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_power_t structure that
 *                  will be populated with power information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_power(fossil_sys_hostinfo_power_t *info);

/**
 * @brief Retrieves general system information.
 *
 * This function fills the fossil_sys_hostinfo_system_t structure with
 * information about the operating system, kernel version, hostname,
 * username, domain name, machine type, and platform.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_system_t structure that
 *                  will be populated with system information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_system(fossil_sys_hostinfo_system_t *info);

/**
 * @brief Retrieves architecture information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_architecture_t structure with
 * details about the system's architecture, such as architecture name, CPU,
 * number of cores and threads, frequency, and CPU architecture.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_architecture_t structure
 *                  that will be populated with architecture information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_architecture(fossil_sys_hostinfo_architecture_t *info);

/**
 * @brief Retrieves memory information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_memory_t structure with
 * details about the system's memory, including total, free, used, and
 * available memory, as well as swap statistics.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_memory_t structure that
 *                  will be populated with memory information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_memory(fossil_sys_hostinfo_memory_t *info);

/**
 * @brief Retrieves endianness information about the host system.
 *
 * This function fills the fossil_sys_hostinfo_endianness_t structure with
 * information indicating whether the system is little-endian or big-endian.
 *
 * @param[out] info Pointer to a fossil_sys_hostinfo_endianness_t structure
 *                  that will be populated with endianness information.
 * @return 0 on success, or a negative error code on failure.
 */
int fossil_sys_hostinfo_get_endianness(fossil_sys_hostinfo_endianness_t *info);

#ifdef __cplusplus
}

/**
 * Fossil namespace.
 */
namespace fossil {

    /**
     * System namespace.
     */
    namespace sys {

        /**
         * Hostinfo management class.
         */
        class Hostinfo {
        public:

            /**
             * @brief Retrieves general system information.
             *
             * This function returns a structure containing details about the
             * operating system, kernel version, hostname, username, domain name,
             * machine type, and platform of the host system.
             *
             * @return A structure containing system information.
             */
            static fossil_sys_hostinfo_system_t get_system() {
                fossil_sys_hostinfo_system_t info;
                fossil_sys_hostinfo_get_system(&info);
                return info;
            }

            /**
             * @brief Retrieves architecture information about the host system.
             *
             * This function returns a structure with details about the system's
             * architecture, such as architecture name, CPU, number of cores and
             * threads, frequency, and CPU architecture.
             *
             * @return A structure containing architecture information.
             */
            static fossil_sys_hostinfo_architecture_t get_architecture() {
                fossil_sys_hostinfo_architecture_t info;
                fossil_sys_hostinfo_get_architecture(&info);
                return info;
            }

            /**
             * @brief Retrieves memory information about the host system.
             *
             * This function returns a structure with details about the system's
             * memory, including total, free, used, and available memory, as well
             * as swap statistics.
             *
             * @return A structure containing memory information.
             */
            static fossil_sys_hostinfo_memory_t get_memory() {
                fossil_sys_hostinfo_memory_t info;
                fossil_sys_hostinfo_get_memory(&info);
                return info;
            }

            /**
             * @brief Retrieves endianness information about the host system.
             *
             * This function returns a structure indicating whether the system is
             * little-endian or big-endian.
             *
             * @return A structure containing endianness information.
             */
            static fossil_sys_hostinfo_endianness_t get_endianness() {
                fossil_sys_hostinfo_endianness_t info;
                fossil_sys_hostinfo_get_endianness(&info);
                return info;
            }

            /**
             * @brief Retrieves CPU information about the host system.
             *
             * This function returns a structure with details about the CPU,
             * including model, vendor, number of cores, threads, frequency, and
             * supported features.
             *
             * @return A structure containing CPU information.
             */
            static fossil_sys_hostinfo_cpu_t get_cpu() {
                fossil_sys_hostinfo_cpu_t info;
                fossil_sys_hostinfo_get_cpu(&info);
                return info;
            }

            /**
             * @brief Retrieves GPU information about the host system.
             *
             * This function returns a structure with details about the GPU,
             * such as name, vendor, driver version, and memory statistics.
             *
             * @return A structure containing GPU information.
             */
            static fossil_sys_hostinfo_gpu_t get_gpu() {
                fossil_sys_hostinfo_gpu_t info;
                fossil_sys_hostinfo_get_gpu(&info);
                return info;
            }

            /**
             * @brief Retrieves power information about the host system.
             *
             * This function returns a structure with details about the system's
             * power state, including AC power status, battery presence, charging
             * state, battery percentage, and estimated time remaining.
             *
             * @return A structure containing power information.
             */
            static fossil_sys_hostinfo_power_t get_power() {
                fossil_sys_hostinfo_power_t info;
                fossil_sys_hostinfo_get_power(&info);
                return info;
            }

            /**
             * @brief Retrieves storage information about the host system.
             *
             * This function returns a structure with details about the system's
             * storage device, such as device name, mount point, total space,
             * free space, used space, and filesystem type.
             *
             * @return A structure containing storage information.
             */
            static fossil_sys_hostinfo_storage_t get_storage() {
                fossil_sys_hostinfo_storage_t info;
                fossil_sys_hostinfo_get_storage(&info);
                return info;
            }

            /**
             * @brief Retrieves environment information for the current user session.
             *
             * This function returns a structure with details such as the user's
             * shell, home directory, language, PATH, terminal type, and username.
             *
             * @return A structure containing environment information.
             */
            static fossil_sys_hostinfo_environment_t get_environment() {
                fossil_sys_hostinfo_environment_t info;
                fossil_sys_hostinfo_get_environment(&info);
                return info;
            }

            /**
             * @brief Retrieves the system uptime information.
             *
             * This function returns a structure with the current uptime details
             * of the host system, including the amount of time (in seconds) that
             * the system has been running since its last boot and the boot time
             * in epoch seconds.
             *
             * @return A structure containing uptime information.
             */
            static fossil_sys_hostinfo_uptime_t get_uptime() {
                fossil_sys_hostinfo_uptime_t info;
                fossil_sys_hostinfo_get_uptime(&info);
                return info;
            }

            /**
             * @brief Retrieves virtualization information about the host system.
             *
             * This function returns a structure with details regarding the
             * virtualization environment, if any, in which the host system is
             * running. This may include information such as the type of hypervisor
             * detected or whether the system is running on bare metal or in a
             * container.
             *
             * @return A structure containing virtualization information.
             */
            static fossil_sys_hostinfo_virtualization_t get_virtualization() {
                fossil_sys_hostinfo_virtualization_t info;
                fossil_sys_hostinfo_get_virtualization(&info);
                return info;
            }

        };

    }

}

#endif

#endif /* FOSSIL_SYS_FRAMEWORK_H */

SAMPLE CODE C #

#include "fossil/sys/hostinfo.h"
##include <stdio.h>

int main(void) {
    fossil_sys_hostinfo_system_t system;
    fossil_sys_hostinfo_cpu_t cpu;
    fossil_sys_hostinfo_memory_t memory;
    fossil_sys_hostinfo_uptime_t uptime;

    if (fossil_sys_hostinfo_get_system(&system) == 0) {
        printf("OS: %s %s\n", system.os_name, system.os_version);
        printf("Kernel: %s\n", system.kernel_version);
        printf("Hostname: %s\n", system.hostname);
        printf("User: %s\n", system.username);
    }

    if (fossil_sys_hostinfo_get_cpu(&cpu) == 0) {
        printf("\nCPU:\n");
        printf("  Model: %s\n", cpu.model);
        printf("  Vendor: %s\n", cpu.vendor);
        printf("  Cores: %d\n", cpu.cores);
        printf("  Threads: %d\n", cpu.threads);
        printf("  Frequency: %.2f GHz\n", cpu.frequency_ghz);
    }

    if (fossil_sys_hostinfo_get_memory(&memory) == 0) {
        printf("\nMemory:\n");
        printf("  Total: %llu MB\n",
               (unsigned long long)(memory.total_memory / (1024 * 1024)));
        printf("  Used:  %llu MB\n",
               (unsigned long long)(memory.used_memory / (1024 * 1024)));
        printf("  Free:  %llu MB\n",
               (unsigned long long)(memory.free_memory / (1024 * 1024)));
    }

    if (fossil_sys_hostinfo_get_uptime(&uptime) == 0) {
        printf("\nUptime: %llu seconds\n",
               (unsigned long long)uptime.uptime_seconds);
    }

    return 0;
}

SAMPLE CODE C++ #

#include "fossil/sys/hostinfo.h"
##include <iostream>

using fossil::sys::Hostinfo;

int main() {
    auto system = Hostinfo::get_system();
    auto cpu = Hostinfo::get_cpu();
    auto memory = Hostinfo::get_memory();
    auto virt = Hostinfo::get_virtualization();
    auto uptime = Hostinfo::get_uptime();

    std::cout << "System:\n";
    std::cout << "  OS: " << system.os_name
              << " " << system.os_version << "\n";
    std::cout << "  Kernel: " << system.kernel_version << "\n";
    std::cout << "  Hostname: " << system.hostname << "\n";

    std::cout << "\nCPU:\n";
    std::cout << "  Model: " << cpu.model << "\n";
    std::cout << "  Cores: " << cpu.cores
              << ", Threads: " << cpu.threads << "\n";
    std::cout << "  Frequency: "
              << cpu.frequency_ghz << " GHz\n";

    std::cout << "\nMemory:\n";
    std::cout << "  Total: "
              << (memory.total_memory / (1024 * 1024)) << " MB\n";
    std::cout << "  Available: "
              << (memory.available_memory / (1024 * 1024)) << " MB\n";

    std::cout << "\nVirtualization:\n";
    if (virt.is_virtual_machine) {
        std::cout << "  VM detected (" << virt.hypervisor << ")\n";
    } else {
        std::cout << "  Bare metal\n";
    }

    if (virt.is_container) {
        std::cout << "  Container: " << virt.container_type << "\n";
    }

    std::cout << "\nUptime: "
              << uptime.uptime_seconds << " seconds\n";

    return 0;
}

What are your feelings

Updated on February 6, 2026