src/bin/psql/command.c
static backslashResult
exec_command_setenv(PsqlScanState scan_state, bool active_branch,
					const char *cmd)
{
	bool		success = true;

	if (active_branch)
	{
		char	   *envvar = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);
		char	   *envval = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);

		if (!envvar)
		{
			pg_log_error("\\%s: missing required argument", cmd);
			success = false;
		}
		else if (strchr(envvar, '=') != NULL)
		{
			pg_log_error("\\%s: environment variable name must not contain \"=\"",
						 cmd);
			success = false;
		}
		else if (!envval)
		{
			/* No argument - unset the environment variable */
			unsetenv(envvar);
			success = true;
		}
		else
		{
			/* Set variable to the value of the next argument */
			setenv(envvar, envval, 1);
			success = true;
		}
		free(envvar);
		free(envval);
	}
	else
		ignore_slash_options(scan_state);

	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
 * \setenv -- set environment variable
 */
\setenv -- set environment variable
\ setenv -- set environment variable
static backslashResult
exec_command_setenv(PsqlScanState scan_state, bool active_branch,
					const char *cmd)
{
	bool		success = true;
	if (active_branch)
	{
		char	   *envvar = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);
		char	   *envval = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);
		if (!envvar)
		{
			pg_log_error("\\%s: missing required argument", cmd);
			success = false;
		}
		else if (strchr(envvar, '=') != NULL)
		{
			pg_log_error("\\%s: environment variable name must not contain \"=\"",
						 cmd);
			success = false;
		}
		else if (!envval)
		{
			unsetenv(envvar);
			success = true;
		}
		else
		{
			setenv(envvar, envval, 1);
			success = true;
		}
		free(envvar);
		free(envval);
	}
	else
		ignore_slash_options(scan_state);
	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
static backslashResult exec_command_setenv ( PsqlScanState scan_state , bool active_branch , const char * cmd ) { bool success = true ; if ( active_branch ) { char * envvar = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ; char * envval = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ; if ( ! envvar ) { pg_log_error ( " \\ " , cmd ) ; success = false ; } else if ( strchr ( envvar , ' ' ) != NULL ) { pg_log_error ( " \\ \" \" " , cmd ) ; success = false ; } else if ( ! envval ) { unsetenv ( envvar ) ; success = true ; } else { setenv ( envvar , envval , 1 ) ; success = true ; } free ( envvar ) ; free ( envval ) ; } else ignore_slash_options ( scan_state ) ; return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ; }
\setenv -- set environment variable
\ setenv -- set environment variable
/* No argument - unset the environment variable */ /* Set variable to the value of the next argument */