menu_new(3MENU)
π menu_new β creating and destroying menu items, bestie edition
okay so we're in the 3MENU manual, section 3, library calls, and this page is literally the origin story of every menu item you will ever make. buckle up π
β¨ NAME β¨
new_item, free_item β the two functions that birth a menu item and then send it to the shadow realm. creation and destruction, main character energy fr fr π
πΈ SYNOPSIS πΈ
#include <menu.h>
ITEM *new_item(const char *name, const char *description);
int free_item(ITEM *item);
look at them. two little icons. one makes, one takes away. balance π¦
π DESCRIPTION π
so new_item allocates a brand new item and initializes it from the name and description pointers. sounds simple right? bestie. listen. π
the item only stores the pointers to the name and description. not copies. pointers. so those pointers have to stay valid for the entire lifetime of the item. the whole time. no cap. π
that means you should be very careful with names or descriptions allocated on the stack of some routines β because the second that stack frame dips out, your pointers are pointing at vibes and nothing else π
and then free_item de-allocates an item. but heads up, queen: it is the responsibility of the application to release the memory for the name or the description of the item. free_item is not doing that for you. it's giving "you're on your own for the strings, bestie" π«Ά
β RETURN VALUE β
new_item returns NULL on error. yes, NULL. and it sets errno according to how it failed:
E_BAD_ARGUMENTβ the routine detected an incorrect or out-of-range argument. like, it looked at what you passed and said "no β€οΈ"E_SYSTEM_ERRORβ a system error occurred, e.g.,mallocfailure. the system simply was not having it today π
and free_item returns one of these:
E_OKβ the routine succeeded. slay! we love a clean exit β¨E_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument.E_CONNECTEDβ the item is connected to a menu. you cannot just free a whole item while it's still in a relationship with a menu, that's messy πE_SYSTEM_ERRORβ a system error occurred (seeerrno(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 an ancient BSD situation... it's not giving. it's not giving at all π
π AUTHORS π
Juergen Pfeifer. and the manual pages and adaptation for new curses were done by Eric S. Raymond. legends, honestly. we stan π
π¦ SEE ALSO π¦
ncurses(3NCURSES)menu(3MENU)
and that's the whole page, bestie!! this was ncurses 6.6, dated 2024-12-28, and it's the menu_new(3MENU) manual β go forth and allocate responsibly, and please, PLEASE keep your string pointers alive πβ¨π
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2023,2024 Thomas E. Dickey
- Copyright 1998-2010,2015 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms