gd_include(3)
π gd_include(3) β GETDATA manual, bestie edition π
okay so this is the gd_include(3) page from the GETDATA manual, and it's a whole saga so we're doing it in two parts. sit down, grab a strawberry π, and let's get into it.
β¨ NAME β¨
gd_include, gd_include_affix, gd_include_ns β the trio that adds a format specification fragment to a Dirfile. slay π
πΈ SYNOPSIS πΈ
#include <getdata.h>
int gd_include(DIRFILE *dirfile, const char *include_file, int
parent_fragment, unsigned long flags);
int gd_include_affix(DIRFILE *dirfile, const char *include_file, int
parent_fragment, const char *prefix, const char *suffix, unsigned
long flags);
int gd_include_ns(DIRFILE *dirfile, const char *include_file, int
parent_fragment, const char *namespace, unsigned long flags);
π¦ DESCRIPTION π¦
okay so the main character here is gd_include_affix(). what it does is take the format specification fragment sitting at the path include_file and add it to the dirfile you're pointing at β and it might even create that fragment, using the affixes you gave it. it's giving "i can do both, i contain multitudes" β¨
this all happens as if, inside the existing fragment indexed by parent_fragment, this directive were just sitting there being its little self:
/INCLUDE <include_file> <prefix> <suffix>
(peep dirfile-format(5) for the lore on that directive, iykyk)
now, about that prefix β it may include a namespace, and that namespace is separated from the rest of the prefix by a dot (.). also the prefix can totally be the empty string, no judgement. π
and if a parser callback function was specified back when the dirfile was opened using gd_cbopen(3), or added later with gd_parser_callback(3), that callback function will get called if a syntax error pops up while parsing the included fragment. so like, heads up.
passing NULL as prefix or suffix is exactly the same as using the empty string (ie. the corresponding affix is empty). lowkey the same vibe either way π«Ά
gd_include()β equivalent to callinggd_include_affix()with bothprefixandsuffixequal toNULL. it's the low-effort version, and honestly? valid.gd_include_ns()β equivalent to callinggd_include_affix()withsuffixequal toNULLandprefixequal tonamespaceconcatenated with a trailing dot. periodt.
π the flags argument
the flags argument should be a bitwise-or'd collection of zero or more of the following flags. yes, zero is allowed, no you don't have to pick one, it's not a vibe check you can fail π
GD_ARM_ENDIAN,GD_NOT_ARM_ENDIANβ specifies that double precision floating point raw data on disk are, or are not, stored in the middle-endian format used by older ARM processors. (iconic legacy behaviour honestly)
these flags only set the default endianness, and they will be overridden when an /ENDIAN directive specifies the byte sex of RAW fields β unless GD_FORCE_ENDIAN is also specified. so don't come crying if your /ENDIAN wins, it's literally supposed to.
on every platform, one of these flags (GD_NOT_ARM_ENDIAN on all but middle-ended ARM systems) indicates the native behaviour of the platform. that symbol will equal zero, and may be omitted. so like, the free one, basically. β¨
GD_BIG_ENDIAN,GD_LITTLE_ENDIANβ specifies the default byte sex of raw data stored on disk to be either big-endian (most significant byte first) or little-endian (least significant byte first). omitting both flags means the default should be the native endianness of the platform. no cap.
unlike the ARM endianness flags above, neither of these symbols is ever zero. specifying both these flags together will cause the library to assume that the endianness of the data is opposite to that of the native architecture, whatever that might be. yes that's real, yes it's chaotic, and yes it's exactly what the manual says π
these flags only set the default endianness, and will be overridden when an /ENDIAN directive specifies the byte sex of RAW fields, unless GD_FORCE_ENDIAN is also specified.
GD_CREATβ an empty fragment will be created, if one does not already exist. the fragment will have modeS_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH(0666), modified by the caller's umask value (seeumask(2)). new fragment just dropped πGD_EXCLβ ensure that this call creates a new fragment: when specified along withGD_CREAT, the call will fail if the file specified byinclude_filealready exists. ifGD_CREATis not specified, this flag isignord. (yes the manpage really saysignord, we love a typo, we stan a typo, we are not fixing it π )
this flag suffers from all the limitations of the O_EXCL flag as indicated in open(2). so, baggage. inherited baggage. π
GD_FORCE_ENCODINGβ specifies that/ENCODINGdirectives (seedirfile-format(5)) found in the fragment should be ignored. the encoding scheme specified inflagswill be used instead (see below).GD_FORCE_ENDIANβ specifies that/ENDIANdirectives (seedirfile-format(5)) found in the fragment should be ignored. when specified with one ofGD_BIG_ENDIANorGD_LITTLE_ENDIAN, the indicated endianness will be assumed. if this flag is specified with neither of those flags, the fragment will be assumed to have the endianness of the native architecture. it's giving "trust me bro, i know what endian this is" πGD_IGNORE_DUPSβ if the fragment specifies more than one field with the same name, or a field with the same name as an existing field, all but one of them will be ignored by the parser. without this flag, parsing would fail with theGD_E_FORMATerror, possibly resulting in invocation of the registered callback function. π
which of the duplicate fields is kept is not specified, nor whether an existing field takes precedence over a new one or not. as a result, this flag is typically only useful in the case where identical copies of a field specification line are present. so like... same line twice? fine. anything sneakier? bestie, you're on your own.
no indication is provided to indicate whether a duplicate field has been discarded. if finer grained control is required, the caller should handle GD_E_FORMAT_DUPLICATE suberrors itself with an appropriate callback function. β¨
GD_IGNORE_REFSβ if the dirfile currently has a reference field (either because one was specified explicitly, or else because the first RAW field was used),/REFERENCEdirectives in the included fragment will be ignored. otherwise, a/REFERENCEdirective in the included fragment will replace the current reference field in the dirfile. swap or skip, pick your fighter πGD_PEDANTICβ specifies that unrecognised lines found during the parsing of the fragment should always cause a fatal error. without this flag, if aVERSIONdirective (seedirfile-format(5)) indicates that the fragment being opened conforms Standards Version newer than the version understood by the library, unrecognised lines will be silently ignored. so this is the "i want to know EVERYTHING" mode. main character energy fr fr πGD_TRUNCβ ifinclude_filealready exists, it will be truncated before opening. if the file does not exist, this flag is ignored. bye bye old contents π
π§ the encoding flags (a whole second buffet)
the flags argument may also be bitwise or'd with one of the following symbols indicating the default encoding scheme of the fragment. like the endianness flags, the choice of encoding here is ignored if the encoding is specified in the fragment itself, unless GD_FORCE_ENCODED is also specified. π«Ά
if none of these symbols is present, GD_AUTO_ENCODED is assumed β unless this call results in creation or truncation of the fragment. in that case, GD_UNENCODED is assumed. see dirfile-encoding(5) for details on dirfile encoding schemes.
GD_AUTO_ENCODEDβ specifies that the encoding type is not known in advance, but should be detected by the GetData library. detection is accomplished by searching for raw data files with extensions appropriate to the encoding scheme. this method will notably fail if the the library is called viagd_putdata(3)to create a previously non-existent raw field β unless a read is first successfully performed on the dirfile. once the library has determined the encoding scheme for the first time, it remembers it for subsequent calls. it's giving "i'll figure it out" and honestly, it usually does π¦GD_BZIP2_ENCODEDβ specifies that raw data files are compressed using the Burrows-Wheeler block sorting text compression algorithm and Huffman coding, as implemented in the bzip2 format.GD_FLAC_ENCODEDβ specifies that raw data files are compressed using the Free Lossless Audio Coded (FLAC). yes, the audio one. for your data. we love a crossover episode π§GD_GZIP_ENCODEDβ specifies that raw data files are compressed using Lempel-Ziv coding (LZ77) as implemented in the gzip format.GD_LZMA_ENCODEDβ specifies that raw data files are compressed using the Lempel-Ziv Markov Chain Algorithm (LZMA) as implemented in the xz container format.GD_SIE_ENCODEDβ specified that raw data files are sample-index encoded, similar to run-length encoding, suitable for data that change rarely. (yes it says "specified", not "specifies", we're keeping it, it's part of the charm π )GD_SLIM_ENCODEDβ specifies that raw data files are compressed using the slimlib library.GD_TEXT_ENCODEDβ specifies that raw data files are encoded as text files containing one data sample per line. cute, readable, yours truly approves β¨GD_UNENCODEDβ specifies that raw data files are not encoded, but written verbatim to disk. raw data staying raw, periodt.GD_ZZIP_ENCODEDβ specifies that raw data files are compressed using the DEFLATE algorithm. all raw data files for a given fragment are collected together and stored in a PKZIP archive calledraw.zip. one zip to hold them all πGD_ZZSLIM_ENCODEDβ specifies that raw data files are compressed using a combinations of compression schemes: first files are slim-compressed, as with theGD_SLIM_ENCODEDscheme, and then they are collected together and compressed (again) into a PKZIP archive calledraw.zip, as in theGD_ZZIP_ENCODEDscheme. double compression, double the slay π
and that's the end of part 1, bestie β there's more coming, so don't go anywhere π
β¨ RETURN VALUE β¨
Okay bestie, here's the tea on what you get back π«Ά
- On success β these functions hand you the format specification index of the freshly-added fragment. Cute, right? That's your little receipt π§Ύ
- On error β you get a negative-valued error code. Not a vibe. Possible error codes are:
GD_E_ACCMODEβ the dirfile you handed over was opened in read-only mode π βοΈ no writing today.GD_E_ALLOCβ the library could not allocate memory. It's giving out-of-ram energy πGD_E_BAD_DIRFILEβ the dirfile you supplied was invalid. Not a real dirfile, bestie πGD_E_BAD_INDEXβ the parent fragment index you supplied was out of range. Too far, babes πGD_E_BAD_REFERENCEβ the reference field specified by a/REFERENCEdirective in the fragment (peepdirfile-format(5)) was not found, or was not aRAWfield. And here's the important bit: in this case, the included fragment will still be added to the dirfile, but the/REFERENCEdirective will be ignored. So like... half-slay? π€GD_E_CALLBACKβ the registered callback function returned an unrecognised response. Rude.GD_E_FORMATβ a syntax error occurred in the fragment. Grammar check failed, periodt βοΈGD_E_LINE_TOO_LONGβ the parser hit a line in the format specification that was longer than it could deal with. Lines are limited by the storage size ofssize_t. On 32-bit systems, that caps format specification lines at2**31characters. The limit is bigger on 64-bit systems. So like, it's very long, but not infinite πGD_E_IOβ an I/O error occured while trying to read or create the fragment. The disk said no π«GD_E_PROTECTEDβ the metadata of the parent fragment was protected from change. Hands off, it's guarded π
The error code is also stashed in the DIRFILE object, so you can go grab it after this function returns by calling gd_error(3). And if you want a whole descriptive error string β like, an actual sentence about what went wrong β call gd_error_string(3) πΈ
π HISTORY π
- The
dirfile_include()function appeared in GetData-0.4.0. - In GetData-0.7.0, this function was renamed to
gd_include(). - The
gd_include_affix()function appeared in GetData-0.8.0. - In GetData-0.10.0, the error return from these functions changed from
-1to a negative-valued error code. Thegd_include_ns()function also appeared in this release. Glow-up era β¨ - See
gd_open(3)for history of the flags. π
π SEE ALSO π
gd_alter_affixes(3), gd_error(3), gd_error_string(3), gd_fragmentname(3), gd_nfragments(3), gd_open(3), gd_parser_callback(3), gd_reference(3), gd_uninclude(3), dirfile(5), dirfile-encoding(5), dirfile-format(5)
and that's the whole page, bestie!! π this one's Version 0.10.0, dated 25 December 2016, and it lives at gd_include(3) π go forth and include your fragments responsibly, ily π¦π
π¦ 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, 2009, 2010, 2011, 2012, 2014, 2016 D. V. Wiebe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms