AMPL_ENVIRONMENT#

group AMPL_ENVIRONMENT

These fuctions provide access to the environment variables and provides facilities to specify where to load the underlying AMPL interpreter.

Typedefs

typedef struct AMPL_Environment AMPL_ENVIRONMENT#

An AMPL Environment.

Functions

int AMPL_EnvironmentVarGetName(AMPL_ENVIRONMENTVAR *envvar, char **name)#

Get the name of an environment variable.

Parameters:
  • envvar – Pointer to the AMPL_ENVIRONMENTVAR struct.

  • name – Pointer to the string where the variable name will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentVarGetValue(AMPL_ENVIRONMENTVAR *envvar, char **value)#

Get the value of an environment variable.

Parameters:
  • envvar – Pointer to the AMPL_ENVIRONMENTVAR struct.

  • value – Pointer to the string where the variable value will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentCreate(AMPL_ENVIRONMENT **env, const char *binaryDirectory, const char *binaryName)#

Allocates the AMPL_ENVIRONMENT struct with ability to select the location of the AMPL binary.

Note that if this function is used, the automatic lookup for an AMPL executable will not be executed.

Parameters:
  • env – Pointer to the pointer of the AMPL_ENVIRONMENT struct.

  • binaryDirectory – The directory in which to look for the AMPL binary.

  • binaryName – The name of the AMPL executable if other than “ampl”.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentFree(AMPL_ENVIRONMENT **env)#

Frees the AMPL_ENVIRONMENT struct.

Parameters:
Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentCopy(AMPL_ENVIRONMENT **copy, AMPL_ENVIRONMENT *src)#

Allocates a copy of an AMPL_ENVIRONMENT struct.

Parameters:
Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentAddEnvironmentVariable(AMPL_ENVIRONMENT *env, const char *name, const char *value)#

Add an environment variable to the environment, or change its value if already defined.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • name – The name of the environment variable.

  • value – The value of the environment variable.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentGetBinaryDirectory(AMPL_ENVIRONMENT *env, char **binaryDirectory)#

Get the location where AMPLAPI will search for the AMPL executable.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • binaryDirectory – Pointer to the string where the binary directory will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentGetAMPLCommand(AMPL_ENVIRONMENT *env, char **amplCommand)#

Get the interpreter that will be used for an AMPL struct constructed using this environment.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • amplCommand – Pointer to the string where the interpreter will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentSetBinaryDirectory(AMPL_ENVIRONMENT *env, const char *binaryDirectory)#

Set the location where AMPLAPI will search for the AMPL executable.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • binaryDirectory – The directory in which to search for the AMPL executable.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentGetBinaryName(AMPL_ENVIRONMENT *env, char **binaryName)#

Get the name of the AMPL executable.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • binaryName – Pointer to the string where the executable name will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentSetBinaryName(AMPL_ENVIRONMENT *env, const char *binaryName)#

Set the name of the AMPL executable.

Parameters:
Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentToString(AMPL_ENVIRONMENT *env, char **str)#

Store all variables into string.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • str – Pointer to the string where the environment variables will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentGetSize(AMPL_ENVIRONMENT *env, size_t *size)#

Get the size of the environment variables.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • size – Pointer to the size of the environment variables will be stored.

Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentGetEnvironmentVar(AMPL_ENVIRONMENT *env, AMPL_ENVIRONMENTVAR **envvar)#

Get the first environment variable in the environment.

Parameters:
Returns:

0 on success, non-zero on failure.

int AMPL_EnvironmentFindEnvironmentVar(AMPL_ENVIRONMENT *env, const char *name, AMPL_ENVIRONMENTVAR **envvar)#

Find an environment variable by name.

Parameters:
  • env – Pointer to the AMPL_ENVIRONMENT struct.

  • name – Name of the environment variable to find.

  • envvar – Pointer to the AMPL_ENVIRONMENTVAR pointer where the result will be stored.

Returns:

0 on success, non-zero on failure.

struct AMPL_ENVIRONMENTVAR#
#include <environment_c.h>

Represents a single environment variable used by the AMPL C API.

This structure stores a name–value pair corresponding to an environment variable. It is typically used to configure or customize the execution environment of the underlying AMPL interpreter, for example to control library paths, licensing, or runtime behavior.

The strings referenced by this structure are expected to be null-terminated. Ownership and lifetime of the strings are managed by the caller unless explicitly stated otherwise.

Public Members

char *name#

Name of the environment variable.

char *value#

Value assigned to the environment variable.