Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/dmenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,32 @@ DMOD_INPUT_API_DECLARATION(dmenv, 1.0, size_t, _count, (dmenv_ctx_t ctx))
*
* @param Name Name of the environment variable
* @param Value Value to set
* @return bool true if successful, false otherwise
* @param Overwrite If non-zero, overwrite existing variable; if zero, keep existing value
* @return int 0 if successful, -1 otherwise
*/
DMOD_INPUT_API_DECLARATION(Dmod, 1.0, bool, _SetEnv, (const char *Name, const char *Value))
DMOD_INPUT_API_DECLARATION(Dmod, 1.0, int, _SetEnv, (const char *Name, const char *Value, int Overwrite))
{
dmenv_ctx_t ctx = dmenv_get_default();
if (ctx == NULL)
{
DMOD_LOG_ERROR("No default context set for Dmod_SetEnv\n");
return false;
return -1;
}

// If Overwrite is 0 and variable already exists, return success without updating
if (Overwrite == 0)
{
const char *existing = dmenv_get(ctx, Name);
if (existing != NULL)
{
DMOD_LOG_VERBOSE("Variable %s already exists, not overwriting\n", Name);
return 0;
}
}
return dmenv_set(ctx, Name, Value);

// Set or update the variable
bool result = dmenv_set(ctx, Name, Value);
return result ? 0 : -1;
}

/**
Expand Down