mitem_new(3X)

πŸ’– mitem_new β€” the ncurses manual, section 3X πŸ’–

okay bestie, so this is mitem_new(3X) from the ncurses library calls, and it's literally all about making and unmaking menu items ✨


🌸 NAME 🌸

new_item, free_item β€” create and destroy menu items. it's giving birth and death but for menu items, no cap πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <menu.h>

ITEM *new_item(const char *name, const char *description);
int free_item(ITEM *item);

✨ DESCRIPTION ✨

so the function new_item allocates a new item and initializes it from the name and description pointers. and bestie, please notice β€” like actually notice β€” that the item stores only the pointers to the name and description. those pointers have to stay valid for the whole entire lifetime of the item πŸ’… so be super careful with names or descriptions that are allocated on the stack of some routine, because that stack memory is gonna dip on you and the item will be left holding a pointer to absolutely nothing 😭 main character energy only in memory that survives, fr fr.

the function free_item de-allocates an item. and again, heads up: it is the responsibility of the application to release the memory for the name or the description of the item. free_item does not do that for you. it's giving "I handled the item, you handle the strings" πŸ‘‘


πŸŽ€ RETURN VALUE πŸŽ€

the function new_item returns NULL on error. it sets errno according to the function's failure:

  • E_BAD_ARGUMENT β€” routine detected an incorrect or out-of-range argument. it's giving "that's not it, bestie" πŸ™ˆ
  • E_SYSTEM_ERROR β€” system error occurred, e.g., malloc failure. πŸ’€

the function free_item returns one of the following:

  • E_OK β€” the routine succeeded. slay ✨
  • E_BAD_ARGUMENT β€” routine detected an incorrect or out-of-range argument.
  • E_CONNECTED β€” item is connected to a menu. not me trying to free something that's still in a relationship πŸ’”
  • E_SYSTEM_ERROR β€” system error occurred (see errno(3)).

🌈 PORTABILITY 🌈

these routines emulate the System V menu library. they were not supported on Version 7 or BSD versions. so if you're on some ancient vibe, they're simply not there 🫢


πŸ‘‘ AUTHORS πŸ‘‘

Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond. iconic work honestly ⭐


🧚 SEE ALSO 🧚

  • curses(3X)
  • menu(3X)

and that's the whole page, bestie πŸ’œ this one's from ncurses 6.6, dated 2024-12-28 β€” go forth and manage your item memory responsibly, because nobody's coming to clean up your strings for you πŸ“πŸ’–

πŸ“¦ where this page comes from