KDK_PRINTE...LABLE_LIST(3)

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

💖 KDK_PRINTE...LABLE_LIST(3) 💖

okay bestie, welcome to the Library Functions Manual, section 3 (that's the library-functions girlies, iykyk) 🎀 this one's all about kdk_printer_get_available_list and honestly? she's giving "let me find you a printer that's actually free rn" ✨


🌸 NAME 🌸

kdk_printer_get_available_list — 获取本地的所有可用打印机(打印机处于idle状态)

like literally, she goes and finds every single printer on your local machine that's actually available — meaning it's sitting in idle state, just vibing, ready to print 🖨️💅


✨ SYNOPSIS ✨

#include <libkyprinter.h>

extern char** kdk_printer_get_available_list();

Link with -lkyprinter.

so yeah, pull in the header, call the function, and don't forget to link with -lkyprinter or the linker will simply not know her 💀


🦋 Detailed Description 🦋

The main function of the interface is to obtain all available printers locally (printers in idle state).

that's the whole assignment bestie — the interface's main character moment is scoping out every local printer that's currently idle, i.e. the ones that aren't busy being dramatic with someone else's job 🔥


👑 RETURN VALUE 👑

On success, returns a list of printer names of type char**, ending with a NULL string; Generated by alloc and needs to be recycled by kdk_printer_freeall

so when it slays, you get back a char** list of printer names, and it's NULL-terminated (a NULL string marks the end, that's your lil stop sign 🛑). important: this list was Generated by alloc, so you have to recycle it with kdk_printer_freeall — not freeing it is giving leak energy, and we don't do that here 🙈

On error, return NULL.

and if things go sideways? you get NULL. that's it. no list, no printers, just NULL and vibes 💀


🌈 EXAMPLES 🌈

here's the full glow-up, verbatim, no notes:

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

int main()
{
    int index = 0;
    //获取全部打印机列表
    char **printers = kdk_printer_get_list();
    while (printers[index])
    {
        int status = kdk_printer_get_status(printers[index]);
        printf("%zd: %s , %d0, index + 1, printers[index], status);
        index++;
    }
    kdk_printer_freeall(printers);
    //获取可用打印机列表
    index = 0;
    char **available_printers = kdk_printer_get_available_list();
    while (available_printers[index])
    {
        int status = kdk_printer_get_status(available_printers[index]);
        printf("%zd: %s , %d0, index + 1, available_printers[index], status);
        index++;
    }
    kdk_printer_freeall(available_printers);

    return 0;
}

see how she does it? grabs the full list with kdk_printer_get_list(), loops till the NULL, prints each one with its status, frees the whole thing with kdk_printer_freeall, then resets index = 0 and does the available version with kdk_printer_get_available_list() — same loop, same cleanup, same energy. obsessed 🫶


🎀 CONFORMING TO 🎀

These functions are as per the withdrawn POSIX.1e draft specification.

(yeah, withdrawn — she's vintage, she's a draft, she's a whole era, don't come for her 💅)

The following functions are Linux extensions:

  • kdk_printer_get_list()
  • kdk_printer_set_options()
  • kdk_printer_print_download_remote_file()
  • kdk_printer_print_local_file()
  • kdk_printer_cancel_all_jobs()
  • kdk_printer_get_status()
  • kdk_printer_get_job_status()
  • kdk_printer_get_filename()
  • kdk_printer_freeall()

those ones? Linux originals. homegrown. iconic ✨


💜 SEE ALSO 💜

go read her friends, they all ate:


⚠️ bestie reminder: that char** you get back is alloc-generated, so kdk_printer_freeall it or it just sits there forever. no cap. 🫶

okay that's the whole page, mwah 💋 this came straight from the Linux Programmer's Manual, dated Fri Aug 25 2023 — go forth and print responsibly, queen 👑🖨️💖

📦 where this page comes from