sdlGetEnvironmentVariable function

String? sdlGetEnvironmentVariable(
  1. Pointer<SdlEnvironment> env,
  2. String? name
)

Get the value of a variable in the environment.

\param env the environment to query. \param name the name of the variable to get. \returns a pointer to the value of the variable or NULL if it can't be found.

\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_GetEnvironmentVariables \sa SDL_SetEnvironmentVariable \sa SDL_UnsetEnvironmentVariable

extern SDL_DECLSPEC const char * SDLCALL SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name)

Implementation

String? sdlGetEnvironmentVariable(Pointer<SdlEnvironment> env, String? name) {
  final sdlGetEnvironmentVariableLookupFunction = libSdl3.lookupFunction<
      Pointer<Utf8> Function(Pointer<SdlEnvironment> env, Pointer<Utf8> name),
      Pointer<Utf8> Function(Pointer<SdlEnvironment> env,
          Pointer<Utf8> name)>('SDL_GetEnvironmentVariable');
  final namePointer = name != null ? name.toNativeUtf8() : nullptr;
  final result = sdlGetEnvironmentVariableLookupFunction(env, namePointer);
  calloc.free(namePointer);
  if (result == nullptr) {
    return null;
  }
  return result.toDartString();
}