Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
7131-kernel-file-Add-read_file-2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 7131-kernel-file-Add-read_file-2.patch of Package erlang
From b4230bea4d743f189c2e23aee1651f4ffd26de74 Mon Sep 17 00:00:00 2001 From: jdamanalo <jamanalo5@up.edu.ph> Date: Wed, 8 Mar 2023 23:54:31 +0800 Subject: [PATCH 1/2] kernel/file: Add read_file/2 --- lib/kernel/doc/src/file.xml | 3 +++ lib/kernel/src/file.erl | 24 +++++++++++++++++++++++- lib/kernel/test/file_SUITE.erl | 6 ++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index a24dcadcb7..e1ae5d85b6 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -1413,13 +1413,16 @@ f.txt: {person, "kalle", 25}. </func> <func> <name name="read_file" arity="1" since=""/> + <name name="read_file" arity="2" since=""/> <fsummary>Read a file.</fsummary> + <type name="read_file_option"/> <desc> <p>Returns <c>{ok, <anno>Binary</anno>}</c>, where <c><anno>Binary</anno></c> is a binary data object that contains the contents of <c><anno>Filename</anno></c>, or <c>{error, <anno>Reason</anno>}</c> if an error occurs.</p> + <p>If the option <c>raw</c> is set, the file server is not called.</p> <p>Typical error reasons:</p> <taglist> <tag><c>enoent</c></tag> diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 3d4422dc2a..fbcc5f839b 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -36,7 +36,8 @@ read_link_info/1, read_link_info/2, read_link/1, read_link_all/1, make_link/2, make_symlink/2, - read_file/1, write_file/2, write_file/3]). + read_file/1, read_file/2, + write_file/2, write_file/3]). %% Specialized -export([ipread_s32bu_p32bu/3]). %% Generic file contents. @@ -125,6 +126,7 @@ -type posix_file_advise() :: 'normal' | 'sequential' | 'random' | 'no_reuse' | 'will_need' | 'dont_need'. -type delete_option() :: 'raw'. +-type read_file_option() :: 'raw'. -type sendfile_option() :: {chunk_size, non_neg_integer()} | {use_threads, boolean()}. -type file_info_option() :: {'time', 'local'} | {'time', 'universal'} @@ -418,6 +420,26 @@ list_dir_all(Name) -> read_file(Name) -> check_and_call(read_file, [file_name(Name)]). +-spec read_file(Filename, Opts) -> {ok, Binary} | {error, Reason} when + Filename :: name_all(), + Opts :: [read_file_option()], + Binary :: binary(), + Reason :: posix() | badarg | terminated | system_limit. + +read_file(Name, Opts) when is_list(Opts) -> + FileName = file_name(Name), + case check_args(Opts) of + ok -> + case lists:member(raw, Opts) of + true -> + ?PRIM_FILE:read_file(FileName); + false -> + call(read_file, [FileName]) + end; + Error -> + Error + end. + -spec make_link(Existing, New) -> ok | {error, Reason} when Existing :: name_all(), New :: name_all(), diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl index 42ff6517a2..dbad5cb92e 100644 --- a/lib/kernel/test/file_SUITE.erl +++ b/lib/kernel/test/file_SUITE.erl @@ -535,6 +535,9 @@ read_write_file(Config) when is_list(Config) -> {error, enoent} = ?FILE_MODULE:read_file(Name2), {error, enoent} = ?FILE_MODULE:read_file(""), {error, enoent} = ?FILE_MODULE:read_file(''), + {error, enoent} = ?FILE_MODULE:read_file(Name2, [raw]), + {error, enoent} = ?FILE_MODULE:read_file("", [raw]), + {error, enoent} = ?FILE_MODULE:read_file('', [raw]), %% Try writing to a bad filename {error, enoent} = do_read_write_file("", Bin2), @@ -559,12 +562,15 @@ do_read_write_file(Name, Data) -> ok -> BinData = iolist_to_binary(Data), {ok,BinData} = ?FILE_MODULE:read_file(Name), + {ok,BinData} = ?FILE_MODULE:read_file(Name, [raw]), ok = ?FILE_MODULE:write_file(Name, Data, []), {ok,BinData} = ?FILE_MODULE:read_file(Name), + {ok,BinData} = ?FILE_MODULE:read_file(Name, [raw]), ok = ?FILE_MODULE:write_file(Name, Data, [raw]), {ok,BinData} = ?FILE_MODULE:read_file(Name), + {ok,BinData} = ?FILE_MODULE:read_file(Name, [raw]), ok; {error,_}=Res -> -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor