From c63a2ff188f661f1738ccd1686d14d1a13aa9335 Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Thu, 11 Sep 2025 15:30:55 +0200 Subject: [PATCH] Add file:native_name_encoding/0 Signed-off-by: Mateusz Front --- libs/estdlib/src/CMakeLists.txt | 1 + libs/estdlib/src/file.erl | 27 ++++++++++++++++++++++ tests/libs/estdlib/CMakeLists.txt | 1 + tests/libs/estdlib/test_file.erl | 37 +++++++++++++++++++++++++++++++ tests/libs/estdlib/tests.erl | 3 ++- 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 libs/estdlib/src/file.erl create mode 100644 tests/libs/estdlib/test_file.erl diff --git a/libs/estdlib/src/CMakeLists.txt b/libs/estdlib/src/CMakeLists.txt index 53369f68e0..50851b5a54 100644 --- a/libs/estdlib/src/CMakeLists.txt +++ b/libs/estdlib/src/CMakeLists.txt @@ -34,6 +34,7 @@ set(ERLANG_MODULES erpc erts_debug ets + file gen_event gen_server gen_statem diff --git a/libs/estdlib/src/file.erl b/libs/estdlib/src/file.erl new file mode 100644 index 0000000000..1b09ee8845 --- /dev/null +++ b/libs/estdlib/src/file.erl @@ -0,0 +1,27 @@ +% +% This file is part of AtomVM. +% +% Copyright 2025 Software Mansion S.A. +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. +% +% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +% + +-module(file). + +-export([native_name_encoding/0]). + +-spec native_name_encoding() -> latin1 | utf8. +native_name_encoding() -> + utf8. diff --git a/tests/libs/estdlib/CMakeLists.txt b/tests/libs/estdlib/CMakeLists.txt index 7554b323d1..dcfded817d 100644 --- a/tests/libs/estdlib/CMakeLists.txt +++ b/tests/libs/estdlib/CMakeLists.txt @@ -49,6 +49,7 @@ set(ERLANG_MODULES test_timer test_supervisor test_lists_subtraction + test_file test_tcp_socket test_udp_socket notify_init_server diff --git a/tests/libs/estdlib/test_file.erl b/tests/libs/estdlib/test_file.erl new file mode 100644 index 0000000000..f9a975389b --- /dev/null +++ b/tests/libs/estdlib/test_file.erl @@ -0,0 +1,37 @@ +% +% This file is part of AtomVM. +% +% Copyright 2025 Tomasz Sobkiewicz +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. +% +% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +% + +-module(test_file). +-export([start/0, test/0]). + +start() -> + test(). + +test() -> + Res = file:native_name_encoding(), + ok = is_proper_encoding(Res), + ok. + +is_proper_encoding(utf8) -> + ok; +is_proper_encoding(latin1) -> + ok; +is_proper_encoding(_) -> + error. diff --git a/tests/libs/estdlib/tests.erl b/tests/libs/estdlib/tests.erl index 761a71b8f8..e26f3b8202 100644 --- a/tests/libs/estdlib/tests.erl +++ b/tests/libs/estdlib/tests.erl @@ -81,7 +81,8 @@ get_non_networking_tests(_OTPVersion) -> test_spawn, test_supervisor, test_lists_subtraction, - test_os + test_os, + test_file ]. get_networking_tests(OTPVersion) when