gd_nentries(3)
๐ gd_nentries(3) โ GETDATA ๐
okay bestie, gather round, because today we are counting entries in a Dirfile and it is going to be so satisfying. this is gd_nentries(3), plus its whole little friend group: gd_nfields, gd_nfields_by_type, gd_nmfields, gd_nmfields_by_type, gd_nmvectors, and gd_nvectors. they all do basically the same thing and honestly? iconic of them.
โจ NAME โจ
gd_nentries, gd_nfields, gd_nfields_by_type, gd_nmfields, gd_nmfields_by_type, gd_nmvectors, gd_nvectors โ count field entries in a Dirfile ๐งฎ
๐ธ SYNOPSIS ๐ธ
#include <getdata.h>
unsigned int gd_nentries(DIRFILE *dirfile, const char *parent, unsigned
int type, unsigned int flags);
unsigned int gd_nfields(DIRFILE *dirfile);
unsigned int gd_nfields_by_type(DIRFILE *dirfile, gd_entype_t type);
unsigned int gd_nmfields(DIRFILE *dirfile, const char *parent);
unsigned int gd_nmfields_by_type(DIRFILE *dirfile, const char *parent,
gd_entype_t type);
unsigned int gd_nmvectors(DIRFILE *dirfile, const char *parent);
unsigned int gd_nvectors(DIRFILE *dirfile);
๐ฆ DESCRIPTION ๐ฆ
so. gd_nentries() looks at a dirfile(5) database โ the one you handed over as dirfile โ and counts how many metadata entries match whatever criteria you gave it. bestie it is literally a counter. it counts. that's the whole vibe. ๐
if parent is non-NULL, we're looking at the metafields hanging out underneath the field named by parent. if parent is NULL? top-level fields only, and metafields get ignored entirely. sorry metafields, not today. ๐
the type argument should be one of these symbols, and it means "count this specific entry type":
GD_BIT_ENTRYGD_CARRAY_ENTRYGD_CONST_ENTRYGD_DIVIDE_ENTRYGD_INDEX_ENTRYGD_INDIR_ENTRYGD_LINCOM_ENTRYGD_LINTERP_ENTRYGD_MPLEX_ENTRYGD_MULTIPLY_ENTRYGD_PHASE_ENTRYGD_POLYNOM_ENTRYGD_RAW_ENTRYGD_RECIP_ENTRYGD_SARRAY_ENTRYGD_SBIT_ENTRYGD_SINDIR_ENTRYGD_STRING_ENTRYGD_WINDOW_ENTRY
(GD_INDEX_ENTRY is a special field type for the implicit INDEX field, iykyk)
...or else it can be one of these special symbols instead:
GD_ALL_ENTRIES(=0) โ count entries of all types. everything. the whole buffet. ๐GD_ALIAS_ENTRIESโ count only aliases. and listen, this is the only way to get a count that includes aliases which don't point to valid field codes. noted. ๐GD_SCALAR_ENTRIESโ count only scalar field types (CONST,CARRAY,SARRAY,STRING).GD_VECTOR_ENTRIESโ count only numeric-valued vector field types (every field type exceptSINDIRand the scalar field types listed above).
then there's flags, which should be zero or more of these, bitwise or'd together:
GD_ENTRIES_HIDDENโ include hidden entries (peep gd_hidden(3)) in the count: normally hidden entries get skipped. sneaky little things. ๐GD_ENTRIES_NOALIASโ exclude aliases from the count: normally aliases count the same as their target (so a field with n aliases, plus its canonical name, gets counted n+1 times). math is math. โจ
also just so you know: this function has a subset of the functionality of the gd_match_entries(3) function (q.v.). it's the chill younger sibling.
๐ Special Cases ๐
the call
gd_nfields(dirfile);
is equivalent to
gd_nentries(dirfile, NULL, GD_ALL_ENTRIES, 0);
the call
gd_nfields_by_type(dirfile, type);
is equivalent to
gd_nentries(dirfile, NULL, type, 0);
the call
gd_nmfields(dirfile, parent);
is equivalent to
gd_nentries(dirfile, parent, GD_ALL_ENTRIES, 0);
the call
gd_nmfields_by_type(dirfile, parent, type);
is equivalent to
gd_nentries(dirfile, parent, type, 0);
the call
gd_nmvectors(dirfile, parent);
is equivalent to
gd_nentries(dirfile, parent, GD_VECTOR_ENTRIES, 0);
the call
gd_nvectors(dirfile);
is equivalent to
gd_nentries(dirfile, NULL, GD_VECTOR_ENTRIES, 0);
๐ RETURN VALUE ๐
when everything goes right, these functions return an unsigned in (yes, the manpage says unsigned in, we are reporting the facts bestie, no edits ๐) telling you the number of entries in the database that satisfied your criteria. slay.
on error, they return zero and stash a negative-valued error code inside the DIRFILE object, which you can grab with a later call to gd_error(3). possible error codes are:
GD_E_BAD_CODEโ theparentfield code you supplied was not found, or it referred to a metafield itself. ๐ซGD_E_BAD_DIRFILEโ thedirfileyou supplied was invalid. not it. ๐ญGD_E_BAD_ENTRYโ thetypeparameter you supplied wasn't one of the symbols listed above. wrong symbol, babe.
heads up: a descriptive error string for the error can be obtained by calling gd_error_string(3). use it, it's giving helpful. ๐ซถ
๐ HISTORY ๐
- the
get_nfields()function appeared in GetData-0.3.0. - the
get_nfields_by_type(),get_nmfields(),get_nmfields_by_type(),get_nmvectors(), andget_nvectors()functions appeared in GetData-0.4.0. - in GetData-0.7.0, these functions were renamed to
gd_nfields(),gd_nfields_by_type(),gd_nmfields(),gd_nmfields_by_type(),gd_nmvectors(), andgd_nvectors(). rebrand era. ๐ - the
gd_nentries()function appeared in GetData-0.8.0.
๐ฅ SEE ALSO ๐ฅ
dirfile(5), gd_open(3), gd_entry_list(3), gd_error(3), gd_error_string(3), gd_hidden(3), gd_match_entries(3)
and that's the whole page bestie!! Version 0.10.0, dated 25 December 2016 โ a little holiday gift from the GETDATA era. go forth and count responsibly. 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) 2012, 2016 D. V. Wiebe
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms