userptr(3MENU)

πŸ’– userptr β€” bestie, let's attach ur data to a menu πŸ’–

okay so this is userptr(3MENU) from the Library calls section, and it's literally the chillest little pair of functions you'll ever meet. no cap. πŸŽ€


✨ NAME ✨

set_menu_userptr, menu_userptr β€” associate application data with a menu item 🫢

like… you get to store your own stuff on a menu. that's it. that's the vibe.


✨ SYNOPSIS ✨

#include <menu.h>

int set_menu_userptr(MENU *menu, void *userptr);
void *menu_userptr(const MENU *menu);

look at that. two little lines. iconic. πŸ‘‘


✨ DESCRIPTION ✨

okay so listen bestie πŸ’… β€” every menu and every menu item has a field that's just… sitting there, waiting for you to put application-specific data in it. and when I say yours, I mean yours, because the menu-driver code leaves it alone. it does not touch it. it does not look at it. it is not nosy. it's giving respectful. 😌

so like, if you want to stash a pointer to your own struct, or a string, or honestly whatever your heart desires β€” that field is where it goes. ✨

and these two functions? they get and set the menu user pointer field. that's the whole job. get it, set it, slay. πŸ¦‹

heads up tho β€” the description says every menu and every menu item has this field. these particular functions are the menu ones, bestie. menu item user pointers live in their own manpage. iykyk. πŸ™ˆ

✨ RETURN VALUE ✨

  • menu_userptr returns a pointer (which may be NULL πŸ’€). and importantly β€” it does not set errno. so don't go blaming errno for anything, it's innocent, it wasn't even there. 🌸
  • set_menu_userptr returns E_OK β€” that's success, babe. it worked. periodt. βœ…

✨ PORTABILITY ✨

okay so the lore πŸ“œ: 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 BSD vibe, sorry bestie, no userptr for you. 😭

and here's the tea about the pointer type πŸ«– β€” the user pointer is a void pointer. they made a whole deliberate choice here: we chose not to leave it as a char pointer for SVr4 compatibility. so yeah, void *, on purpose, for the compatibility. not a typo, not a glow-up gone wrong, it's intentional. πŸ’…


✨ AUTHORS ✨

Juergen Pfeifer. πŸ’œ

Manual pages and adaptation for new curses by Eric S. Raymond. 🌈

absolute legends, fr fr. give them their flowers. πŸ’


✨ SEE ALSO ✨

  • ncurses(3NCURSES) ⭐
  • menu(3MENU) πŸŽ€

go read those next, bestie, they're part of the same friend group.


and that's the whole page!! ✨ this was ncurses 6.6, dated 2024-12-28, and yeah it's literally the userptr(3MENU) page β€” thanks for reading, ily, go store some pointers responsibly πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from