Skip to content

Commit c63a2ff

Browse files
committed
Add file:native_name_encoding/0
Signed-off-by: Mateusz Front <mateusz.front@swmansion.com>
1 parent 94503ed commit c63a2ff

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

libs/estdlib/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(ERLANG_MODULES
3434
erpc
3535
erts_debug
3636
ets
37+
file
3738
gen_event
3839
gen_server
3940
gen_statem

libs/estdlib/src/file.erl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Software Mansion S.A.
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(file).
22+
23+
-export([native_name_encoding/0]).
24+
25+
-spec native_name_encoding() -> latin1 | utf8.
26+
native_name_encoding() ->
27+
utf8.

tests/libs/estdlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(ERLANG_MODULES
4949
test_timer
5050
test_supervisor
5151
test_lists_subtraction
52+
test_file
5253
test_tcp_socket
5354
test_udp_socket
5455
notify_init_server

tests/libs/estdlib/test_file.erl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Tomasz Sobkiewicz <tomasz.sobkiewicz@swmansion.com>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(test_file).
22+
-export([start/0, test/0]).
23+
24+
start() ->
25+
test().
26+
27+
test() ->
28+
Res = file:native_name_encoding(),
29+
ok = is_proper_encoding(Res),
30+
ok.
31+
32+
is_proper_encoding(utf8) ->
33+
ok;
34+
is_proper_encoding(latin1) ->
35+
ok;
36+
is_proper_encoding(_) ->
37+
error.

tests/libs/estdlib/tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ get_non_networking_tests(_OTPVersion) ->
8181
test_spawn,
8282
test_supervisor,
8383
test_lists_subtraction,
84-
test_os
84+
test_os,
85+
test_file
8586
].
8687

8788
get_networking_tests(OTPVersion) when

0 commit comments

Comments
 (0)