Skip to content

Conversation

mat-hek
Copy link
Contributor

@mat-hek mat-hek commented Aug 20, 2025

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

These changes are made under both the "Apache 2.0" and the "GNU Lesser
General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

Implemented file:native_name_encoding/0 nif.
Copied PRIMITIVE_UTF8_CHECK from
https://github.com/erlang/otp/blob/OTP-26.0.2/erts/emulator/sys/common/erl_sys_common_misc.c.
- I am open for better ideas.

Signed-off-by: Mateusz Front <[email protected]>

static bool env_equals(const char *env_var, const char *value)
{
const char *env_value = getenv(env_var);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POSIX says getenv is not thread safe. You need to hold global->env_spinlock.

UNUSED(ctx)
UNUSED(argc)
UNUSED(argv)
if (env_equals("LC_ALL", "UTF-8") || env_equals("LC_CTYPE", "UTF-8") || env_equals("LANG", "UTF-8")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this implementation. We could simply always return utf8, couldn't we? The most important part here is the documentation of the function.

@mat-hek mat-hek changed the title Add file:native_name_encoding/0 (#93) Add file:native_name_encoding/0 Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants