KDK_PACKAGE_GET_PACKAGELIST(3)

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

✨ NAME ✨

kdk_package_get_packagelist — 获取系统中所有包列表 (that's "grab the list of every package on the system" bestie, it's giving inventory-core 💅)

This one lives in the Library Functions Manual section, page 3, okurrr. 🎀


🌸 SYNOPSIS 🌸

#include <libkypackages.h>

extern kdk_package_list* kdk_package_get_packagelist();

Link with -lkypackage.


🦋 Detailed Description 🦋

Okay so the whole ~main character~ job of this interface? It gets you a list of all packages in the system. That's it. That's the function. No cap, it's just the master roster of everything installed. 👑


💖 RETURN VALUE 💖

When it slays (success), you get back a pointer to a kdk_package_list structure, and that structure is holding gateway information. 🫶

The kdk_package_list structure is defined in <libkypackages.h> like this, fr fr:

typedef struct {
    unsigned int nums;
    kdk_package_t **list;
}kdk_package_list;

typedef struct _kdk_package_t{
    char *name;     // 包名
    char *version;  // 版本号
    char *section;  // 包类型
    char *status;   // 状态
    unsigned long size_kb;   // 包大小
    struct _kdk_package_t **depends; // 依赖包
}kdk_package_t;

When it does not slay (error), it returns NULL. 😭

Heads up bestie: NULL means check before you dereference, or it's over for you 💀

🌈 EXAMPLES 🌈

Here's the whole vibe in code form, copied exactly because I respect the source 💜

#include "libkypackages.h"
#include <stdio.h>

static void print_package(kdk_package_t *package)
{
    printf("包名:%s", package->name);
    printf("版本号:%s", package->version);
    printf("包类型:%s", package->section);
    printf("包状态:%s", package->status);
    printf("包大小:%lu0, package->size_kb);
}

int main()
{
    kdk_package_list *list = kdk_package_get_packagelist();
    printf("系统中一共%u个软件包0, list->nums);
    for (size_t i = 0; i < list->nums; i ++)
    {
        print_package(list->list[i]);
    }
    kdk_package_free_packagelist(list);

    printf("Evolution是否安装:%s0, kdk_package_is_installed("evolution", NULL) == 1 ? "是" : "否");
    char *version = kdk_package_get_version("evolution");
    printf("Evolution版本号:%s0, version);
    free(version);

    return 0;
}

Like, it prints every package, then checks if Evolution is installed, then peeks at its version. Iconic behaviour honestly. ⭐


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. Yes, withdrawn — it's a vintage moment, we stan a retro spec. 🙈

The following functions are Linux extensions:

  • kdk_package_free_packagelist()
  • kdk_package_get_version()
  • kdk_package_is_installed()

💅 SEE ALSO 💅


That's the whole page, bestie! This one came from the Linux Programmer's Manual, dated Mon Sep 18 2023. Go forth and enumerate your packages, you absolute queen. 🧚✨

📦 where this page comes from