mitem_new(3X)
π
mitem_new β the curses menu-item origin story π
okay so this is the mitem_new(3X) page from the library calls section, and it's literally about making and unmaking menu items. bestie, it's giving "birth and death of an ITEM" and honestly? iconic.
β¨ NAME β¨
new_item, free_item β create and destroy menu items π¦
πΈ SYNOPSIS πΈ
#include <menu.h>
ITEM *new_item(const char *name, const char *description);
int free_item(ITEM *item);
π DESCRIPTION π
so new_item allocates a brand-new item and initializes it from the name and description pointers. cute, right? but here's the catch, and it's a big one β the item stores ONLY the pointers to the name and description. it does not copy the strings. it does not clone them. it justβ¦ holds onto your pointers like a bestie holding your hand π«Ά.
those pointers must be valid for the entire lifetime of the item. so like, be SO careful with names or descriptions that are allocated on the stack of some routine, because the moment that routine returns, your item is holding a pointer to a ghost π» and that's a whole situation you do not want.
free_item de-allocates an item. and ngl, this part is on you: it is the responsibility of the application to release the memory for the name or the description of the item. free_item frees the ITEM, not your strings. those are yours to manage, bestie, no cap π
.
β RETURN VALUE β
new_item returns NULL on error π and sets errno according to whatever went wrong:
E_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument.E_SYSTEM_ERRORβ system error occurred, e.g.,mallocfailure π.
then free_item returns one of these:
E_OKβ the routine succeeded β¨ periodt.E_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument.E_CONNECTEDβ item is connected to a menu π (so like, you can't just free it while it's still linked up, that's messy).E_SYSTEM_ERRORβ system error occurred (seeerrno(3)).
π§ PORTABILITY π§
these routines emulate the System V menu library. they were not supported on Version 7 or BSD versions. iykyk π¦.
π AUTHORS π
Juergen Pfeifer. manual pages and adaptation for new curses by Eric S. Raymond. absolute main characters, we stan π.
π₯ SEE ALSO π₯
curses(3X), menu(3X)
okay that's the whole page, mwah π β this one's from ncurses 6.5, dated 2024-12-28, so you know it's fresh π. go forth and manage your pointers responsibly, bestie π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2018-2023,2024 Thomas E. Dickey
- Copyright 1998-2010,2015 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms