Back to libut API Reference


SYNOPSIS

    #include "libut/ut.h"
    int UT_var_set(char *name, value);


DESCRIPTION

This function sets the value of the configuration variable having the given name to the specified value which must be an int, double, or char*, depending on whether the configuration variable is of type UT_var_int, UT_var_double, or UT_var_string, respectively.

If the configuration variable has a callback that was established using UT_var_reg_cb(3) or a restriction placed upon it using UT_var_restrict(3) then the new value is subject to being accepted or rejected by the callback or restriction. If the value is rejected (e.g., because it was outside of an allowed numeric range) the original value of the variable is retained.

Warning: Use decimals (e.g., pass 1.0 instead of 1) when setting a a UT_var_double type to a literal value. This is necessary in a variable-length argument list, as the compiler cannot tell 1 is meant as a double unless it is passed as 1.0. The binary format of int and double are completely different and the value will be set incorrectly if a double is not passed where it is expected. (The same issue can be observed using printf(3). The code printf("1 is not %f", 1); prints ``1 is not -1.998432''!)


RETURN VALUE

A return value equal to or greater than 0 indicates success. A negative return value means the change was not accepted by the variable's callback or restriction conditions.

If name refers to a configuration variable that doesn't exist, it logged as a Fatal error, and the application exits with exit status -1.


RELATED CONTROL PORT COMMANDS

The var control port command lists and sets the configuration variables.


SEE ALSO

UT_var_create(3), UT_var_get(3), UT_var_bindc(3), UT_var_reg_cb(3), UT_var_restrict(3)


AUTHOR

Troy D. Hanson <thanson@users.sourceforge.net>