{"size": 5494, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/scribblings/reference/envvars.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/scribblings/reference/envvars.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/scribblings/reference/envvars.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 41.6212121212, "max_line_length": 76, "alphanum_fraction": 0.7125955588}
#lang scribble/doc
@(require "mz.rkt")

@title[#:tag "envvars"]{Environment Variables}

An @deftech{environment variable set} encapsulates a partial mapping
from byte strings to byte strings. A Racket process's initial
@tech{environment variable set} is connected to the operating system's
environment variables: accesses or changes to the set read or change
operating-system environment variables for the Racket process.

Since Windows environment variables are case-insensitive,
@tech{environment variable set}'s key byte strings on Windows are
case-folded. More precisely, key byte strings are coerced to a UTF-8
encoding of characters that are converted to lowercase via
@racket[string-locale-downcase].

The current @tech{environment variable set}, which is determined by
the @racket[current-environment-variables] parameter, is propagated to
a @tech{subprocess} when the @tech{subprocess} is created.


@defproc[(environment-variables? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is an @tech{environment variable
set}, @racket[#f] otherwise.}


@defparam[current-environment-variables env environment-variables?]{

A @tech{parameter} that determines the @tech{environment variable set}
that is propagated to a @tech{subprocess} and that is used as the
default set for @racket[getenv] and @racket[putenv].}


@defproc[(bytes-environment-variable-name? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is a byte string and if it is valid
for an environment variable name. An environment variable name must
contain no bytes with the value @racket[0] or @racket[61], where
@racket[61] is @racket[(char->integer #\=)]. On Windows, an
environment variable name also must have a non-zero length.}


@defproc[(make-environment-variables [name bytes-environment-variable-name?]
                                     [val bytes-no-nuls?]
                                     ... ...)
         environment-variables?]{

Creates a fresh @tech{environment variable set} that is initialized
with the given @racket[name] to @racket[val] mappings.}


@defproc[(environment-variables-ref [env environment-variables?]
                                    [name bytes-environment-variable-name?])
         (or/c #f (and/c bytes-no-nuls? immutable?))]{

Returns the mapping for @racket[name] in @racket[env], returning
@racket[#f] if @racket[name] has no mapping.

Normally, @racket[name] should be a byte-string encoding of a string
using the default encoding of the current @tech{locale}. On Windows,
@racket[name] is coerced to a UTF-8 encoding and case-normalized.}


@defproc[(environment-variables-set! [env environment-variables?]
                                     [name bytes-environment-variable-name?]
                                     [maybe-bstr (or/c bytes-no-nuls? #f)]
                                     [fail (-> any)
                                           (lambda ()
                                             (raise (make-exn:fail ....)))])
         any]{

Changes the mapping for @racket[name] in @racket[env] to
@racket[maybe-bstr].  If @racket[maybe-bstr] is @racket[#f] and
@racket[env] is the initial @tech{environment variable set} of the
Racket process, then the operating system environment-variable mapping
for @racket[name] is removed.

Normally, @racket[name] and @racket[maybe-bstr] should be a
byte-string encoding of a string using the default encoding of the
current @tech{locale}. On Windows, @racket[name] is
coerced to a UTF-8 encoding and case-normalized, and
@racket[maybe-bstr] is coerced to a UTF-8 encoding if @racket[env] is
the initial @tech{environment variable set} of the Racket process.

On success, the result of @racket[environment-variables-set!] is
@|void-const|. If @racket[env] is the initial @tech{environment
variable set} of the Racket process, then attempting to adjust the
operating system environment-variable mapping might fail for some reason,
in which case @racket[fail] is called in tail position with respect to the
@racket[environment-variables-set!]. The default @racket[fail] raises
an exception.}


@defproc[(environment-variables-names [env environment-variables?])
         (listof (and/c bytes-environment-variable-name? immutable?))]{

Returns a list of byte strings that corresponds to names mapped by
@racket[env].}


@defproc[(environment-variables-copy [env environment-variables?])
         environment-variables?]{

Returns an @tech{environment variable set} that is initialized with
the same mappings as @racket[env].}


@deftogether[(
@defproc[(getenv [name string-environment-variable-name?])
                 (or/c string-no-nuls? #f)]
@defproc[(putenv [name string-environment-variable-name?]
                 [value string-no-nuls?]) boolean?]
)]{

Convenience wrappers for @racket[environment-variables-ref] and
@racket[environment-variables-set!] that convert between strings and
byte strings using the current @tech{locale}'s default encoding (using
@racket[#\?] as the replacement character for encoding errors) and
always using the current @tech{environment variable set} from
@racket[current-environment-variables]. The @racket[putenv] function
returns @racket[#t] for success and @racket[#f] for failure.}


@defproc[(string-environment-variable-name? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is a string and if its encoding
using the current @tech{locale}'s encoding is valid for an environment
variable name according to @racket[bytes-environment-variable-name?].}

