Skip to content

Commit d8d0b49

Browse files
committed
Add env var manipulation functions to SDL_stdinc
1 parent 3741143 commit d8d0b49

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

units/SDL_stdinc.inc

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,248 @@ procedure SDL_aligned_free(mem: Pointer); cdecl;
501501
function SDL_GetNumAllocations(): cint; cdecl;
502502
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetNumAllocations' {$ENDIF} {$ENDIF};
503503
504+
(* -- Environment variables manipulation functions -- *)
505+
506+
type
507+
PPSDL_Environment = ^PSDL_Environment;
508+
{*
509+
* A thread-safe set of environment variables
510+
*
511+
* \since This struct is available since SDL 3.2.0.
512+
*
513+
* \sa SDL_GetEnvironment
514+
* \sa SDL_CreateEnvironment
515+
* \sa SDL_GetEnvironmentVariable
516+
* \sa SDL_GetEnvironmentVariables
517+
* \sa SDL_SetEnvironmentVariable
518+
* \sa SDL_UnsetEnvironmentVariable
519+
* \sa SDL_DestroyEnvironment
520+
*}
521+
PSDL_Environment = type Pointer;
522+
523+
{*
524+
* Get the process environment.
525+
*
526+
* This is initialized at application start and is not affected by setenv()
527+
* and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and
528+
* SDL_UnsetEnvironmentVariable() if you want to modify this environment, or
529+
* SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist
530+
* in the C runtime environment after SDL_Quit().
531+
*
532+
* \returns a pointer to the environment for the process or NIL on failure;
533+
* call SDL_GetError() for more information.
534+
*
535+
* \threadsafety It is safe to call this function from any thread.
536+
*
537+
* \since This function is available since SDL 3.2.0.
538+
*
539+
* \sa SDL_GetEnvironmentVariable
540+
* \sa SDL_GetEnvironmentVariables
541+
* \sa SDL_SetEnvironmentVariable
542+
* \sa SDL_UnsetEnvironmentVariable
543+
*}
544+
function SDL_GetEnvironment(): PSDL_Environment; cdecl;
545+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetEnvironment' {$ENDIF} {$ENDIF};
546+
547+
{**
548+
* Create a set of environment variables
549+
*
550+
* \param populated true to initialize it from the C runtime environment,
551+
* false to create an empty environment.
552+
* \returns a pointer to the new environment or NIL on failure; call
553+
* SDL_GetError() for more information.
554+
*
555+
* \threadsafety If `populated` is false, it is safe to call this function
556+
* from any thread, otherwise it is safe if no other threads are
557+
* calling setenv() or unsetenv()
558+
*
559+
* \since This function is available since SDL 3.2.0.
560+
*
561+
* \sa SDL_GetEnvironmentVariable
562+
* \sa SDL_GetEnvironmentVariables
563+
* \sa SDL_SetEnvironmentVariable
564+
* \sa SDL_UnsetEnvironmentVariable
565+
* \sa SDL_DestroyEnvironment
566+
*}
567+
function SDL_CreateEnvironment(populated: Boolean): PSDL_Environment; cdecl;
568+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateEnvironment' {$ENDIF} {$ENDIF};
569+
570+
{*
571+
* Get the value of a variable in the environment.
572+
*
573+
* \param env the environment to query.
574+
* \param name the name of the variable to get.
575+
* \returns a pointer to the (read-only) value of the variable
576+
* or NIL if it can't be found.
577+
*
578+
* \threadsafety It is safe to call this function from any thread.
579+
*
580+
* \since This function is available since SDL 3.2.0.
581+
*
582+
* \sa SDL_GetEnvironment
583+
* \sa SDL_CreateEnvironment
584+
* \sa SDL_GetEnvironmentVariables
585+
* \sa SDL_SetEnvironmentVariable
586+
* \sa SDL_UnsetEnvironmentVariable
587+
*}
588+
function SDL_GetEnvironmentVariable(env: PSDL_Environment; const name: PAnsiChar): PAnsiChar; cdecl;
589+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetEnvironmentVariable' {$ENDIF} {$ENDIF};
590+
591+
{*
592+
* Get all variables in the environment.
593+
*
594+
* \param env the environment to query.
595+
* \returns a NIL terminated array of pointers to environment variables in
596+
* the form "variable=value" or NIL on failure; call SDL_GetError()
597+
* for more information. This is a single allocation that should be
598+
* freed with SDL_free() when it is no longer needed.
599+
*
600+
* \threadsafety It is safe to call this function from any thread.
601+
*
602+
* \since This function is available since SDL 3.2.0.
603+
*
604+
* \sa SDL_GetEnvironment
605+
* \sa SDL_CreateEnvironment
606+
* \sa SDL_GetEnvironmentVariables
607+
* \sa SDL_SetEnvironmentVariable
608+
* \sa SDL_UnsetEnvironmentVariable
609+
*}
610+
function SDL_GetEnvironmentVariables(env: PSDL_Environment): PPAnsiChar; cdecl;
611+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetEnvironmentVariables' {$ENDIF} {$ENDIF};
612+
613+
{**
614+
* Set the value of a variable in the environment.
615+
*
616+
* \param env the environment to modify.
617+
* \param name the name of the variable to set.
618+
* \param value the value of the variable to set.
619+
* \param overwrite true to overwrite the variable if it exists, false to
620+
* return success without setting the variable if it already
621+
* exists.
622+
* \returns true on success or false on failure; call SDL_GetError() for more
623+
* information.
624+
*
625+
* \threadsafety It is safe to call this function from any thread.
626+
*
627+
* \since This function is available since SDL 3.2.0.
628+
*
629+
* \sa SDL_GetEnvironment
630+
* \sa SDL_CreateEnvironment
631+
* \sa SDL_GetEnvironmentVariable
632+
* \sa SDL_GetEnvironmentVariables
633+
* \sa SDL_UnsetEnvironmentVariable
634+
*}
635+
function SDL_SetEnvironmentVariable(env: PSDL_Environment; const name, value: PAnsiChar; overwrite: Boolean): Boolean; cdecl;
636+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetEnvironmentVariable' {$ENDIF} {$ENDIF};
637+
638+
{*
639+
* Clear a variable from the environment.
640+
*
641+
* \param env the environment to modify.
642+
* \param name the name of the variable to unset.
643+
* \returns true on success or false on failure; call SDL_GetError() for more
644+
* information.
645+
*
646+
* \threadsafety It is safe to call this function from any thread.
647+
*
648+
* \since This function is available since SDL 3.2.0.
649+
*
650+
* \sa SDL_GetEnvironment
651+
* \sa SDL_CreateEnvironment
652+
* \sa SDL_GetEnvironmentVariable
653+
* \sa SDL_GetEnvironmentVariables
654+
* \sa SDL_SetEnvironmentVariable
655+
* \sa SDL_UnsetEnvironmentVariable
656+
*}
657+
function SDL_UnsetEnvironmentVariable(env: PSDL_Environment; const name: PAnsiChar): Boolean; cdecl;
658+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnsetEnvironmentVariable' {$ENDIF} {$ENDIF};
659+
660+
{*
661+
* Destroy a set of environment variables.
662+
*
663+
* \param env the environment to destroy.
664+
*
665+
* \threadsafety It is safe to call this function from any thread, as long as
666+
* the environment is no longer in use.
667+
*
668+
* \since This function is available since SDL 3.2.0.
669+
*
670+
* \sa SDL_CreateEnvironment
671+
*}
672+
procedure SDL_DestroyEnvironment(env: PSDL_Environment); cdecl;
673+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroyEnvironment' {$ENDIF} {$ENDIF};
674+
675+
{*
676+
* Get the value of a variable in the environment.
677+
*
678+
* This function uses SDL's cached copy of the environment and is thread-safe.
679+
*
680+
* \param name the name of the variable to get.
681+
* \returns a pointer to the (read-only) value of the variable
682+
* or NIL if it can't be found.
683+
*
684+
* \threadsafety It is safe to call this function from any thread.
685+
*
686+
* \since This function is available since SDL 3.2.0.
687+
*}
688+
function SDL_getenv(const name: PAnsiChar): PAnsiChar; cdecl;
689+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_getenv' {$ENDIF} {$ENDIF};
690+
691+
{*
692+
* Get the value of a variable in the environment.
693+
*
694+
* This function bypasses SDL's cached copy of the environment and is not
695+
* thread-safe.
696+
*
697+
* \param name the name of the variable to get.
698+
* \returns a pointer to the (read-only) value of the variable
699+
* or NIL if it can't be found.
700+
*
701+
* \threadsafety This function is not thread safe, consider using SDL_getenv()
702+
* instead.
703+
*
704+
* \since This function is available since SDL 3.2.0.
705+
*
706+
* \sa SDL_getenv
707+
*}
708+
function SDL_getenv_unsafe(const name: PAnsiChar): PAnsiChar; cdecl;
709+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_getenv_unsafe' {$ENDIF} {$ENDIF};
710+
711+
{*
712+
* Set the value of a variable in the environment.
713+
*
714+
* \param name the name of the variable to set.
715+
* \param value the value of the variable to set.
716+
* \param overwrite 1 to overwrite the variable if it exists, 0 to return
717+
* success without setting the variable if it already exists.
718+
* \returns 0 on success, -1 on error.
719+
*
720+
* \threadsafety This function is not thread safe, consider using
721+
* SDL_SetEnvironmentVariable() instead.
722+
*
723+
* \since This function is available since SDL 3.2.0.
724+
*
725+
* \sa SDL_SetEnvironmentVariable
726+
*}
727+
function SDL_setenv_unsafe(const name, value: PAnsiChar; overwrite: cint): cint; cdecl;
728+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_setenv_unsafe' {$ENDIF} {$ENDIF};
729+
730+
{*
731+
* Clear a variable from the environment.
732+
*
733+
* \param name the name of the variable to unset.
734+
* \returns 0 on success, -1 on error.
735+
*
736+
* \threadsafety This function is not thread safe, consider using
737+
* SDL_UnsetEnvironmentVariable() instead.
738+
*
739+
* \since This function is available since SDL 3.2.0.
740+
*
741+
* \sa SDL_UnsetEnvironmentVariable
742+
*}
743+
function SDL_unsetenv_unsafe(const name: PAnsiChar): cint; cdecl;
744+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_unsetenv_unsafe' {$ENDIF} {$ENDIF};
745+
504746
(* -- Floating-point arithmetic functions -- *)
505747

506748
{*

0 commit comments

Comments
 (0)