gd_constants(3)
β¨ NAME β¨
okay so hi bestie π this is the GetData page for gd_constants(3) β it's gd_constants, gd_mconstants, and their whole thing is retrieving a list of constant values from a Dirfile. iconic behaviour, honestly.
π SYNOPSIS π
#include <getdata.h>
const void *gd_constants(DIRFILE *dirfile, gd_type_t return_type);
const void *gd_mconstants(DIRFILE *dirfile, const char *parent,
gd_type_t return_type);
πΈ DESCRIPTION πΈ
So gd_constants() looks up a dirfile(5) database β that's the one you hand it as dirfile β and then it goes and compiles a whole lil list of the values of all the CONST fields defined in that database. Meta subfields are NOT invited to this party, okay? Excluded. Periodt. π
βοΈ
Then all those values get converted into whatever data type you asked for with return_type. And return_type has to be one of these symbols, no substitutions bestie:
GD_UINT8, GD_INT8, GD_UINT16, GD_INT16, GD_UINT32, GD_INT32,
GD_UINT64, GD_INT64, GD_FLOAT32, GD_FLOAT64, GD_COMPLEX64,
GD_COMPLEX128.
If you're like "what do these even mean" β go check gd_get_constant(3), it explains every single one π«Ά.
Oh and the dirfile argument has to point to a valid DIRFILE object that was already created by a call to gd_open(3). No fake ones, no guessing.
Meanwhile gd_mconstants() is the meta-subfield girlie π
β it hands you that same kinda list, but for the CONST meta subfields of the parent field you name in parent.
And if you want the matching list of names for these fields? Call gd_field_list_by_type(3) or gd_mfield_list_by_type(3). Matching set, slay. β¨
π RETURN VALUE π
When everything goes right, gd_constants() gives you back a pointer to an array holding the values of all the constants defined in the dirfile database. Same deal with gd_mconstants() β pointer to an array, this time with the values of all the meta subfield constants of the parent field you specified. π
okay important: the list that comes back should not be assumed to be in any particular order. BUT β and this is the cute part β it is guaranteed to be in the same order as the list ofCONSTfields returned bygd_field_list_by_type(3)orgd_mfield_list_by_type(3). So they match up. cute.
Also the array is unterminated β there's no lil sentinel at the end telling you where it stops, so don't go looking for one. The number of values in the array comes from calling gd_nfields_by_type(3) or gd_nmfields_by_type(3), whichever one fits your situation. π§
Memory for that returned array is managed by GetData, so do NOT de-allocate it yourself. And the caller may not modify any values in the array β like, actually, doing so may cause database corruption ππ so please don't.
The pointer is guaranteed valid only until the function is called again β with one exception, and it's a good one: since each top-level field maintains its own arrays, calling gd_mconstants() for one parent field does not invalidate the pointer you got back for any other parent. π«Ά
If you go and modify the dirfile's metadata, that invalidates any pointer these functions returned. And no pointers stay valid after the dirfile gets de-allocated by a call to gd_close(3) or gd_discard(3). Once a pointer is invalidated, the caller should not dereference it. like, at all. don't. π
If there are no constants of the appropriate class defined in the database, you get NULL back β and ngl, that is not considered an error. it's just a vibe. no constants, no problem.
But on actual error, these functions return NULL and stash a negative-valued error code in the DIRFILE object, which you can grab with a later call to gd_error(3). Possible error codes, here we go:
GD_E_ALLOCβ the library couldn't allocate memory. πGD_E_BAD_CODEβ the parent field code you specified wasn't found, or it referred to a metafield. (This one isgd_mconstants()only, bestie.)GD_E_BAD_DIRFILEβ the dirfile you handed over was invalid. π«GD_E_BAD_TYPEβ the return_type you specified was not one of the symbols listed above. go pick a real one.GD_E_INTERNAL_ERRORβ an internal error happened inside the library while it was trying to do the task. This indicates a bug in the library. Please re-port the incident to the GetData developers! ππ
And if you want a descriptive error string for whatever went down, call gd_error_string(3). π
π¦ HISTORY π¦
The functions get_constants() and get_mconstants() appeared way back in GetData-0.4.0. β¨
Then in GetData-0.7.0, they got renamed to gd_constants() and gd_mconstants(). glow-up era. π
π SEE ALSO π
gd_error(3), gd_error_string(3), gd_field_list_by_type(3), gd_get_constant(3), gd_mfield_list_by_type(3), gd_nfields_by_type(3), gd_nmfields_by_type(3), gd_open(3), dirfile(5)
and that's the whole page bestie!! π this was Version 0.10.0, dated 25 December 2016 β the gd_constants(3) GETDATA moment, no cap. go read your constants. mwah ππ
π¦ where this page comes from
- debian bookworm: libgetdata-doc 0.11.0-6
- debian trixie: libgetdata-doc 0.11.0-15
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- nixos 26.05: getdata 0.11.0
- nixpkgs unstable: getdata 0.11.0
- ubuntu jammy: libgetdata-doc 0.11.0-3ubuntu1
- ubuntu noble: libgetdata-doc 0.11.0-13
- ubuntu questing: libgetdata-doc 0.11.0-15
- ubuntu resolute: libgetdata-doc 0.11.0-17build1
- ubuntu stonking: libgetdata-doc 0.11.0-17build2
- Copyright (C) 2016 D. V. Wiebe
- Copyright (C) 2008, 2010, 2011, 2015, 2016 D.V. Wiebe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms