@@ -88,6 +88,7 @@ using namespace std::literals::string_literals;
88
88
89
89
using android::base::Basename;
90
90
using android::base::SetProperty;
91
+ using android::base::Split;
91
92
using android::base::StartsWith;
92
93
using android::base::StringPrintf;
93
94
using android::base::unique_fd;
@@ -968,6 +969,23 @@ static Result<void> do_copy(const BuiltinArguments& args) {
968
969
return {};
969
970
}
970
971
972
+ static Result<void > do_copy_per_line (const BuiltinArguments& args) {
973
+ std::string file_contents;
974
+ if (!android::base::ReadFileToString (args[1 ], &file_contents, true )) {
975
+ return Error () << " Could not read input file '" << args[1 ] << " '" ;
976
+ }
977
+ auto lines = Split (file_contents, " \n " );
978
+ for (const auto & line : lines) {
979
+ auto result = WriteFile (args[2 ], line);
980
+ if (!result.ok ()) {
981
+ LOG (VERBOSE) << " Could not write to output file '" << args[2 ] << " ' with '" << line
982
+ << " ' : " << result.error ();
983
+ }
984
+ }
985
+
986
+ return {};
987
+ }
988
+
971
989
static Result<void > do_chown (const BuiltinArguments& args) {
972
990
auto uid = DecodeUid (args[1 ]);
973
991
if (!uid.ok ()) {
@@ -1366,6 +1384,7 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
1366
1384
{" class_start_post_data" , {1 , 1 , {false , do_class_start_post_data}}},
1367
1385
{" class_stop" , {1 , 1 , {false , do_class_stop}}},
1368
1386
{" copy" , {2 , 2 , {true , do_copy}}},
1387
+ {" copy_per_line" , {2 , 2 , {true , do_copy_per_line}}},
1369
1388
{" domainname" , {1 , 1 , {true , do_domainname}}},
1370
1389
{" enable" , {1 , 1 , {false , do_enable}}},
1371
1390
{" exec" , {1 , kMax , {false , do_exec}}},
0 commit comments