---
name: "gensio_add_default"
section: "3"
platform: "linux"
package: "gensio"
version: "3.0.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/gensio_add_default"
---

# gensio\_add\_default(3)

Handle default values for gensios

## 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);**

  ## DESCRIPTION

Defaults provide a way to set overall or class-based defaults for gensio options (or you can use it yourself to create your own defaults).  The various options for gensios are described in [gensio(5)](/gensio/5.md).

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.  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.

Any option provided in the gensio string will override any default value, of course.

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.*

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.* 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. If the value is *\<minval* or *\>maxval,* *GE\_OUTOFRANGE* is returned from any set operation.

When setting a str, the value is copied, you don't have to keep the copy around for yourself.

When getting a string value, the value is duplicated with **gensio\_strdup,** you should free it with **o-\>free().**

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().**

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.

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.

Setting the same default again will replace the old value.

**gensio\_del\_default** deletes the given default.  You can only delete user-added defaults, not ones created by the gensio library.  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.

**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.

**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.

## RETURN VALUES

Zero is returned on success, or a gensio error on failure.

## SEE ALSO

[gensio\_err(3)](/gensio_err/3.md), [gensio(5)](/gensio/5.md)
