<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=4 sw=4 et tw=99 ft=cpp:
 */

#include "ejs-process.h"
#include "ejs-array.h"
#include "ejs-gc.h"
#include "ejs-function.h"
#include "ejs-string.h"
#include "ejs-error.h"

#include <unistd.h>
#include <string.h>
#include <sys/param.h>

extern char** environ;

static ejsval
_ejs_Process_get_env (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    ejsval env_obj = _ejs_object_new(_ejs_null, &_ejs_Object_specops);

    char** p = environ;

    while (*p) {
        char *env_entry = strdup(*p);
        char *eq = strchr(env_entry, '=');
        if (!eq) {
            free (env_entry);
            p++;
            continue;
        }

        *eq = '\0';

        ejsval k = _ejs_string_new_utf8(env_entry);
        ejsval v = _ejs_string_new_utf8(eq+1);

        _ejs_object_define_value_property (env_obj, k, v, EJS_PROP_ENUMERABLE | EJS_PROP_NOT_CONFIGURABLE | EJS_PROP_NOT_WRITABLE);
        free (env_entry);
        p++;
    }

    return env_obj;<commit_msg>no need to malloc/free here - just use _ejs_string_new_utf8_len<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=4 sw=4 et tw=99 ft=cpp:
 */

#include "ejs-process.h"
#include "ejs-array.h"
#include "ejs-gc.h"
#include "ejs-function.h"
#include "ejs-string.h"
#include "ejs-error.h"

#include <unistd.h>
#include <string.h>
#include <sys/param.h>

extern char** environ;

static ejsval
_ejs_Process_get_env (ejsval env, ejsval _this, uint32_t argc, ejsval *args)
{
    ejsval env_obj = _ejs_object_new(_ejs_null, &_ejs_Object_specops);

    char** p = environ;

    while (*p) {
        char *env_entry = *p;
        char *eq = strchr(env_entry, '=');
        if (!eq) {
            p++;
            continue;
        }

        ejsval k = _ejs_string_new_utf8_len(env_entry, eq - env_entry);
        ejsval v = _ejs_string_new_utf8(eq+1);

        _ejs_object_define_value_property (env_obj, k, v, EJS_PROP_ENUMERABLE | EJS_PROP_NOT_CONFIGURABLE | EJS_PROP_NOT_WRITABLE);
        p++;
    }

    return env_obj;
{'fraction_non_alphanumeric': 0.14318921431892143, 'fraction_numerical': 0.011157601115760111, 'mean_word_length': 2.9558823529411766, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3586370', 'n_tokens_mistral': 890, 'n_tokens_neox': 872, 'n_words': 180}