Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
env_all.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
18
19case OP_ENV_ALL: {
20 extern char **environ;
22 if (environ) {
23 for (char **env = environ; *env; ++env) {
24 char *entry = *env;
25 char *equals = strchr(entry, '=');
26 if (equals) {
27 size_t key_len = equals - entry;
28 char *key = malloc(key_len + 1);
29 if (key) {
30 memcpy(key, entry, key_len);
31 key[key_len] = '\0';
32 map_set(&m, key, make_string(equals + 1));
33 free(key);
34 }
35 }
36 }
37 }
39 break;
40}
@ OP_ENV_ALL
Definition bytecode.h:147
push_value(vm, m)
Value m
Definition has_key.c:27
free(vals)
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Definition map.c:79
Value make_map_empty(void)
Construct a new empty map Value.
Definition map.c:35
Tagged union representing a Fun value.
Definition value.h:68
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95