gensio_add_default(3)
π gensio_add_default π
okay bestie, welcome to the Library Functions Manual, section 3 β yes we're in the C library zone, get comfy, grab a boba π§, because this page is literally all about defaults and honestly? it eats.
πΈ NAME πΈ
gensio_add_default, gensio_set_default, gensio_get_default, gensio_get_defaultaddr, gensio_del_default, gensio_reset_defaults β Handle default values for gensios β¨
π SYNOPSIS π
#include <gensio/gensio.h>
struct gensio_enum_val {
char *name;
int val;
};
int gensio_add_default(struct gensio_os_funcs *o,
const char *name,
enum gensio_default_type type,
const char *strval, int intval,
int minval, int maxval,
const struct gensio_enum_val *enums);
int gensio_set_default(struct gensio_os_funcs *o,
const char *class, const char *name,
const char *strval, int intval);
int gensio_get_default(struct gensio_os_funcs *o,
const char *class, const char *name,
bool classonly,
enum gensio_default_type type,
char **strval, int *intval);
int gensio_get_defaultaddr(struct gensio_os_funcs *o,
const char *class, const char *name,
bool classonly,
int iprotocol, bool listen,
bool require_port,
struct addrinfo **rai);
int gensio_del_default(struct gensio_os_funcs *o,
const char *class, const char *name,
bool delclasses);
int gensio_reset_defaults(struct gensio_os_funcs *o);
no cap, that's the whole squad of functions right there π
π¦ DESCRIPTION π¦
Defaults are the vibe where you set overall defaults or class-based defaults for gensio options β and yes, you can also use this whole thing yourself to create your very own defaults, main character energy fr. The various options for gensios are described over in gensio(5) if you wanna go read the lore.
For default values, each class will use gensio_get_default with their class (serialdev, telnet, ssl, etc.) with the name as the given option name. So here's the tea β: if a value has been set for its class, it will use that value. If a value has been set with class set to NULL (a "global" default) then the value will be used from there. Otherwise the code will use it's own internal default value. periodt.
Any option provided in the gensio string will override any default value, of course. obviously π
The classonly parameter means to not look in the global defaults. If you use this for your own defaults, it is recommended that you use your own class and set classonly to true. do that, bestie, trust π
Defaults come in one of four formats defined by type: GENSIO_DEFAULT_INT, GENSIO_DEFAULT_BOOL, GENSIO_DEFAULT_ENUM, GENSIO_DEFAULT_STR, GENSIO_DEFAULT_DATA. (the page says four and then lists five, and honestly we are simply not going to question the source material π)
int and bool are pretty self-explanatory. Except that if you pass in a non-NULL strval when setting one, the code will attempt to get the value from the strval and will return NULL if the value is not valid. It will attempt to translate "true" and "false" for bool values. And if the value is <minval or >maxval, GE_OUTOFRANGE is returned from any set operation. so like, stay in your range π«Ά
When setting a str, the value is copied, you don't have to keep the copy around for yourself. so you can just let it go, it's fine π
When getting a string value, the value is duplicated with gensio_strdup, you should free it with o->free(). do not forget this one β that's a memory leak, and a memory leak is not the vibe π
Data is like strings, except the length is passed in intval and it is returned the same way. This will hold arbitrary raw data. Like strings, when you get a data value you should free it with o->free(). same rule, same energy π
If it's a enum, setting the value you will pass in a string and a table of possible values in enum (terminated with a NULL name). The code will look up the string you pass in in the enums table, and set the value to the integer value. If the string is not in the enums table, it will return GE_INVAL. When you get the value, it will return the value in intval. cute and efficient, obsessed β¨
When getting the value, the type must match what is set in the set call. If the name is not found, GE_NOTFOUND is returned. If the type does not match, then GE_INVAL is returned. Note that if you save a value as an enum, you can fetch it as an int. slay, flexible π
Setting the same default again will replace the old value. out with the old, in with the new π
gensio_del_default deletes the given default. You can only delete user-added defaults, not ones created by the gensio library β that's not yours to touch, bestie. If there are any class-specific default registered against the default, this call will fail with GE_INUSE unless delclasses is true, which will cause all the class defaults to be deleted, too. so like, know what you're doing before you flip that switch π
gensio_reset_defaults will reset all defaults to the value set when gensio_add_default was called to create the default, or the built-in default value. factory reset but make it fancy π
gesnio_get_defaultaddr gets an address from the given default string. See gensi_scan_network_port in gensio/gensio.h for details on how the string is formatted, what the parameters mean, and how to handle the addrinfo struct. (those two names are spelled exactly like the page spells them β we reproduce, we do not editorialize π)
β RETURN VALUES β
Zero is returned on success, or a gensio error on failure. that's it, that's the whole story π₯
π SEE ALSO π
and that's the page, bestie π it came from the Library Functions Manual and it was last touched 27 Feb 2019 β shoutout to gensio_add_default(3) for keeping the defaults in check all this time, iconic behavior, no notes πβ¨
π¦ where this page comes from
- alpine 3.22: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- alpine 3.23: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- alpine 3.24: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- arch rolling: gensio 3.0.4-1 Β· GPL
- debian bookworm: libgensio-dev 2.6.2-4 Β· GPL-2.0-only
- debian trixie: libgensio-dev 2.8.13-7 Β· GPL-2.0-only
- epel 9: libgensio-devel 2.8.15-1.el9 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 2.8.15-5.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 2.8.15-5.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 3.0.4-1.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 3.0.4-1.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.2-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.2-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.4-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.4-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- nixos 26.05: gensio 3.0.2
- nixpkgs unstable: gensio 3.0.2
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- ubuntu jammy: libgensio-dev 2.3.5-1build2 Β· GPL-2.0-only
- ubuntu noble: libgensio-dev 2.8.2-6.1build1 Β· GPL-2.0-only
- ubuntu questing: libgensio-dev 2.8.13-7
- ubuntu resolute: libgensio-dev 3.0.0-1build1 Β· GPL-2.0-only
- ubuntu stonking: libgensio-dev 3.0.0-1ubuntu1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms