silc_global_set_var
SYNOPSIS
void *silc_global_set_var(const char *name, SilcUInt32 variable_size, void *initial_value, SilcBool tls);
DESCRIPTION
Sets a variable of size of `variable_size' bytes as a global variable under the name of `name'. If `initial_value' is non-NULL it is considered to be the initial value of the stored variable. If it is NULL this will initialize the variable as all zeroes.
If variable with `name' already exists it will be replaced with the `initial_value' or as all zeroes, and the old pointer will become invalid.
If `tls' is FALSE the variable is visible to all threads in the process. If it is TRUE the variable is visible only in the current thread. The variable can be retrieved using the same name by calling the silc_global_get_var.
Returns NULL and sets silc_errno if the variable could not be added, or a pointer to the added variable otherwise.
EXAMPLE
// Initialize global buffer silc_global_set_var("somebuf", 256, NULL, FALSE); // Retrieve the buffer unsigned char *buf = silc_global_get_var("somebuf", FALSE); // Set integer global SilcUInt32 integer = 100; silc_global_set_var("someint", 4, &integer, FALSE); // Retrieve the integer and change its value SilcUInt32 *intptr = silc_global_get_var("someint", FALSE); *intptr = 200; // Set structure as global in the thread silc_global_set_var("somestruct", sizeof(*context), NULL, TRUE); // Retrieve the context context = silc_global_get_var("somestruct", TRUE);