KDK_PACKAGE_GET_VERSION(3)

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

✨ KDK_PACKAGE_GET_VERSION 💅

okay so bestie, we're in section 3 of the library functions manual today, and this one is kdk_package_get_version — she lives in <libkynetinfo.h> and she's here to tell you what version of a package is on the system. no cap. 🎀


🌸 NAME 🌸

kdk_package_get_version — 获取系统中指定包的版本号 (aka: grab the version number of a package you name, straight from the system) 🦋


✨ SYNOPSIS ✨

#include <libkynetinfo.h>

extern char* kdk_package_get_version(const char *name);

Link with -lkynetinfo. 🔗


💖 DETAILED DESCRIPTION 💖

The main character job of this interface is literally just: get the version number of the package you specify in the system. that's it, that's the whole vibe. 👑

The argument name is the package name. you hand her a name, she hands you a version. periodt.


🫶 RETURN VALUE 🫶

On success, she returns the version of type char * — and bestie, listen, the returned string needs to be released by free. like, you have to clean up after her, she's not doing it for you. 🙈

On error, she returns NULL. no version for you, sorry. 💀


🌈 EXAMPLES 🌈

here's the whole thing in action, copy-paste coded and everything:

#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;
}

see that free(version) at the end? yeah. that's the receipt. don't lose it. 🧾✨


👑 CONFORMING TO 👑

These functions are as per the withdrawn POSIX.1e draft specification. yes, withdrawn, we don't make the rules. 😭

The following functions are Linux extensions:

  • kdk_package_get_packagelist()
  • kdk_package_free_packagelist()
  • kdk_package_is_installed()

🦋 SEE ALSO 🦋


and that's the whole page, bestie. 🎀 this lil masterpiece comes to you from the Linux Programmer's Manual, dated Mon Sep 18 2023 — iconic behavior, honestly. go free your strings. 💜

📦 where this page comes from