sdlSetEnvironmentVariable function

bool sdlSetEnvironmentVariable(
  1. Pointer<SdlEnvironment> env,
  2. String? name,
  3. String? value,
  4. bool overwrite,
)

Set the value of a variable in the environment.

\param env the environment to modify. \param name the name of the variable to set. \param value the value of the variable to set. \param overwrite true to overwrite the variable if it exists, false to return success without setting the variable if it already exists. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.1.3.

\sa SDL_GetEnvironment \sa SDL_CreateEnvironment \sa SDL_GetEnvironmentVariable \sa SDL_GetEnvironmentVariables \sa SDL_UnsetEnvironmentVariable

extern SDL_DECLSPEC bool SDLCALL SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite)

Implementation

bool sdlSetEnvironmentVariable(
    Pointer<SdlEnvironment> env, String? name, String? value, bool overwrite) {
  final sdlSetEnvironmentVariableLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(Pointer<SdlEnvironment> env, Pointer<Utf8> name,
          Pointer<Utf8> value, Uint8 overwrite),
      int Function(Pointer<SdlEnvironment> env, Pointer<Utf8> name,
          Pointer<Utf8> value, int overwrite)>('SDL_SetEnvironmentVariable');
  final namePointer = name != null ? name.toNativeUtf8() : nullptr;
  final valuePointer = value != null ? value.toNativeUtf8() : nullptr;
  final result = sdlSetEnvironmentVariableLookupFunction(
          env, namePointer, valuePointer, overwrite ? 1 : 0) ==
      1;
  calloc.free(namePointer);
  calloc.free(valuePointer);
  return result;
}