KDK_HW_FREE_HW(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

💖 KDK_HW_FREE_HW 💖

okay bestie, we're in section 3 of the Library Functions Manual, and this one's a cleanup icon, no cap 🧹✨


✨ NAME ✨

kdk_hw_free_hw — 释放kdk_hw_get_hwinfo返回的硬件信息结构体

like, literally the girl whose whole job is releasing the hardware info struct that kdk_hw_get_hwinfo handed you. she's the designated driver of the friend group 🫶


🌸 SYNOPSIS 🌸

#include <libkyhw.h>

extern void kdk_hw_free_hw(struct HWInfo *list);

Link with -lkyhwinfo.

bestie you GOTTA link with -lkyhwinfo or she simply will not show up to the function call. periodt 💅

🦋 Detailed Description 🦋

The main function of the interface is to release the hardware information structure returned by the kdk_hw_get_hwinfo.

The argument list is the return value of the kdk_hw_get_hwinfo.

so basically: kdk_hw_get_hwinfo gives you the struct, and kdk_hw_free_hw takes it back. it's giving "you borrowed my hoodie, now give it back" energy 🙈 hand her the list, that's the whole vibe.


⭐ RETURN VALUE ⭐

No return value

she returns NOTHING. silence. mystery. main character energy 👑


🎀 EXAMPLES 🎀

here's the full little demo, copy it exactly bestie, i'm not editing a single character of it, iykyk:

#include "libkyhw.h"
#include <stdio.h>
#include <string.h>

static _print_hw(struct HWInfo *hw)
{
    struct HWInfo *tmp = hw;
    while (tmp)
    {
        printf("model : %s0, tmp->model);
        printf("vendor : %s0, tmp->vendor);
        printf("device : %s0, tmp->device);
        printf("driver : %s0, tmp->driver);
        printf("revision : %s0, tmp->revision);
        printf("devicenum : %s0, tmp->devicenum);
        printf("clock : %s0, tmp->clock);
        printf("width : %s0, tmp->width);
        tmp = tmp->next;
    }
}

static void Traverse_hardware()
{
    struct HWInfo *keyboard = kdk_hw_get_hwinfo(3);
    printf("KeyBoard Info:0);
    _print_hw(keyboard);
    kdk_hw_free_hw(keyboard);

    struct HWInfo *mouse = kdk_hw_get_hwinfo(5);
    printf("Mouse Info:0);
    _print_hw(mouse);
    kdk_hw_free_hw(mouse);

    struct HWInfo *bound = kdk_hw_get_hwinfo(15);
    printf("Bound Info:0);
    _print_hw(bound);
    kdk_hw_free_hw(bound);

    struct HWInfo *cdrom = kdk_hw_get_hwinfo(23);
    printf("CDRom Info:0);
    _print_hw(cdrom);
    kdk_hw_free_hw(cdrom);

    struct HWInfo *camera = kdk_hw_get_hwinfo(27);
    printf("Camera Info:0);
    _print_hw(camera);
    kdk_hw_free_hw(camera);
}

static void Traverse_power()
{
    struct Power * power = kdk_hw_get_powerinfo();
    printf("on_battery : %s0, power->on_battery ? "true" : "false");
    printf("lid_is_closed : %s0, power->lid_is_closed ? "true" : "false");
    printf("lid_is_present : %s0, power->lid_is_present ? "true" : "false");
    printf("daemon version : %s0, power->daemon_version);
    printf("critical action : %s0, power->critical_action);

    struct power_device *tmp = power->devices;
    while (tmp)
    {
        printf("name : %s0, tmp->name);
        printf("native path : %s0, tmp->native_path);
        printf("power supply : %s0, tmp->power_supply ? "true" : "false");
        printf("updated : %s0, tmp->updated);
        printf("has history : %s0, tmp->has_history ? "true" : "false");
        printf("has statistics : %s0, tmp->has_statistics ? "true" : "false");
        printf("is persent: %s0, tmp->is_persent ? "true" : "false");
        printf("is rechargeable : %s0, tmp->is_rechargeable ? "true" : "false");
        printf("state : %s0, tmp->state);
        printf("waring level : %s0, tmp->warning_level);
        printf("energy : %0.2f0, tmp->energy);
        printf("energy empty : %0.2f0, tmp->energy_empty);
        printf("energy full: %0.2f0, tmp->energy_full);
        printf("energy full design : %0.2f0, tmp->energy_full_design);
        printf("energy rate : %0.2f0, tmp->energy_rate);
        printf("voltage : %0.2f0, tmp->voltage);
        printf("time to empty : %ld0, tmp->time_to_empty);
        printf("time to full : %ld0, tmp->time_to_full);
        printf("percentage : %0.2f0, tmp->percentage);
        printf("temperature : %0.2f0, tmp->temperature);
        printf("capacity : %0.2f0, tmp->capacity);
        printf("technology : %s0, tmp->technology);
        printf("online : %s0, tmp->online ? "true" : "false");
        printf("icon name : %s0, tmp->icon_name);
        tmp = tmp->next;
    }
    kdk_hw_free_power_info(power);
}

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        printf("please use like >> kyhwinfo-test --[target]0);
        printf("hardware");
        printf("power");
        printf("0);
        return 0;
    }
    if (0 == strcmp(argv[1], "--hardware"))
        Traverse_hardware();
    if (0 == strcmp(argv[1], "--power"))
        Traverse_power();
}

see how Traverse_hardware() grabs a keyboard, a mouse, a bound, a cdrom and a camera, prints them, then hands every single one back to kdk_hw_free_hw? that's the whole point bestie. you borrow, you print, you FREE. no leaks in this household 🧚 and yeah, Traverse_power() uses kdk_hw_free_power_info instead, because power info has its own cleanup girl 💜


🌈 CONFORMING TO 🌈

These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: kdk_hw_get_hwinfo(), kdk_hw_get_powerinfo() and kdk_hw_free_power_info().

bestie the POSIX.1e draft is withdrawn, okay? and those three functions up there are Linux extensions, so don't go expecting them on every platform, fr fr 😭

💅 SEE ALSO 💅

kdk_hw_get_hwinfo(3), kdk_hw_get_powerinfo(3) and kdk_hw_free_power_info(3).

the whole little friend group: one gives you the struct, one gives you the power info, one frees the power info, and our girl frees the hw info. slay 💖


that's the tea from the Linux Programmer's Manual, dated Fri Aug 25 2023 🎀✨ go forth and free your structs, bestie, no cap 🫶💜

📦 where this page comes from