File 0842-ssh-Reorg-and-fixes-in-ssh_xfer.patch of Package erlang

From 760d78f7f695a7710b825497f9f1a387ce062e6b Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Thu, 9 Jan 2020 13:43:02 +0100
Subject: [PATCH 3/3] ssh: Reorg and fixes in ssh_xfer

---
 lib/ssh/src/ssh.hrl            | 3 +++
 lib/ssh/src/ssh_connection.erl | 7 +------
 lib/ssh/src/ssh_sftp.erl       | 2 +-
 lib/ssh/src/ssh_xfer.erl       | 6 +++---
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/ssh/src/ssh.hrl b/lib/ssh/src/ssh.hrl
index 86c447f695..a9d81f7252 100644
--- a/lib/ssh/src/ssh.hrl
+++ b/lib/ssh/src/ssh.hrl
@@ -70,6 +70,9 @@
 -define(string_utf8(X), << ?STRING(unicode:characters_to_binary(X)) >> ).
 -define(binary(X), << ?STRING(X) >>).
 
+%% Other macros
+-define(to_binary(X), (try iolist_to_binary(X) catch _:_ -> unicode:characters_to_binary(X) end) ).
+
 -define(SSH_CIPHER_NONE, 0).
 -define(SSH_CIPHER_3DES, 3).
 -define(SSH_CIPHER_AUTHFILE, ?SSH_CIPHER_3DES).
diff --git a/lib/ssh/src/ssh_sftp.erl b/lib/ssh/src/ssh_sftp.erl
index 342a2e012d..97dd333089 100644
--- a/lib/ssh/src/ssh_sftp.erl
+++ b/lib/ssh/src/ssh_sftp.erl
@@ -1621,7 +1621,7 @@ lseek_pos(_, _, _) ->
 
 %%%================================================================
 %%%
-to_bin(Data) when is_list(Data) -> unicode:characters_to_binary(Data);
+to_bin(Data) when is_list(Data) -> ?to_binary(Data);
 to_bin(Data) when is_binary(Data) -> Data.
 
 
diff --git a/lib/ssh/src/ssh_xfer.erl b/lib/ssh/src/ssh_xfer.erl
index b071b38be2..2292beaf68 100644
--- a/lib/ssh/src/ssh_xfer.erl
+++ b/lib/ssh/src/ssh_xfer.erl
@@ -93,7 +93,7 @@ write(XF,ReqID, Handle, Offset, Data) ->
 		is_binary(Data) ->
 		    Data;
 		is_list(Data) -> 
-		    unicode:characters_to_binary(Data)
+		    ?to_binary(Data)
 	    end,
     xf_request(XF,?SSH_FXP_WRITE,
 	       [?uint32(ReqID),
@@ -233,7 +233,7 @@ xf_request(XF, Op, Arg) ->
 	       is_binary(Arg) -> 
 		   Arg;
 	       is_list(Arg) ->
-		   list_to_binary(Arg)
+		   ?to_binary(Arg)
 	   end,
     Size = 1+size(Data),
     ssh_connection:send(CM, Channel, [<<?UINT32(Size), Op, Data/binary>>]).
@@ -243,7 +243,7 @@ xf_send_reply(#ssh_xfer{cm = CM, channel = Channel}, Op, Arg) ->
 	       is_binary(Arg) ->
 		   Arg;
 	       is_list(Arg) ->
-		   list_to_binary(Arg)
+		   ?to_binary(Arg)
 	   end,
     Size = 1 + size(Data),
     ssh_connection:send(CM, Channel, [<<?UINT32(Size), Op, Data/binary>>]).
-- 
2.16.4

openSUSE Build Service is sponsored by