GENDERS_TESTATTR(3)

πŸŽ€ GENDERS_TESTATTR(3) β€” LIBGENDERS πŸŽ€

okay bestie, pull up a chair, we're doing libgenders section 3 today πŸ’…


✨ NAME ✨

genders_testattr β€” literally just: does this node have this attribute or not? that's the whole vibe check πŸ¦‹


🌸 SYNOPSIS 🌸

#include <genders.h>

int genders_testattr(genders_t handle, const char *node, const char *attr, char *val, int len);

int genders_testattrval(genders_t handle, const char *node, const char *attr, const char *val);

πŸ’– DESCRIPTION πŸ’–

so. genders_testattr() asks the big question: does the node that node points at contain the attribute that attr points at? 🫢 and if node is NULL? no worries, it just tests the current node, main character energy fr.

if the attribute IS found, its value gets stashed in the buffer that val points to. and len? that's you telling it how long that buffer is, no cap. don't actually need the value? set val to NULL and move on, iconic.

🚨 bestie listen: to avoid passing in an attribute value buffer that is not large enough to store the attribute value, you should use genders_getmaxvallen(3) to figure out the minimum buffer size you should be using. do not skip this. i'm begging.

genders_testattrval() goes one step further β€” it tests if the node pointed to by node contains the attribute pointed to by attr and if that attribute is equal to the attribute value pointed to by val. and if val is NULL? then it only tests the attribute itself, simple as 🌈


⭐ RETURN VALUES ⭐

for genders_testattr():

  • if the node contains the attribute β†’ 1 is returned πŸ’š
  • if the node does not contain the attribute β†’ 0 is returned

for genders_testattrval():

  • if the node contains the attribute and it is equal to the attribute value β†’ 1 is returned πŸ’š
  • 0 is returned if the node does not contain the attribute, or if the attribute is not equal to the attribute value

and for both genders_testattr() and genders_testattrval(): -1 is returned on error 😭 and an error code is returned in handle. you can grab that error code with genders_errnum(3), and get a lil description of it with genders_strerror(3). error codes are defined in genders.h, iykyk.


πŸ’€ ERRORS πŸ’€

  • GENDERS_ERR_NULLHANDLE β€” the handle parameter is NULL. the genders handle has to be created with genders_handle_create(3) first, babe.
  • GENDERS_ERR_NOTLOADED β€” genders_load_data(3) has not been called to load genders data. nothing loaded, nothing to test 🫠
  • GENDERS_ERR_OVERFLOW β€” the buffer pointed to by val is not large enough to store the attribute value. told you to call genders_getmaxvallen(3) πŸ™ˆ
  • GENDERS_ERR_PARAMETERS β€” an incorrect parameter has been passed in.
  • GENDERS_ERR_NOTFOUND β€” the node pointed to by node cannot be found in the genders file, or if node=NULL, the machine genders is running on is not listed in the genders database. ghosted πŸ’€
  • GENDERS_ERR_MAGIC β€” handle has an incorrect magic number. either handle does not point to a genders handle, or handle has been destroyed by genders_handle_destroy(3). it's giving expired ✨

πŸ“ FILES πŸ“

  • /usr/include/genders.h

πŸ”₯ SEE ALSO πŸ”₯

libgenders(3), genders_handle_create(3), genders_load_data(3), genders_getmaxvallen(3), genders_errnum(3), genders_strerror(3)


and that's the whole page, bestie!! πŸŽ€βœ¨ this one's brought to you by LLNL, dated August 2003 (yes she's vintage, vintage is chic πŸ’…), living in the LIBGENDERS manual, section 3. go test some attributes, you absolute icon πŸ‘‘πŸ’œ