From 8fff4a245e57cd2e3479a35cf5a8be534bee5e1c Mon Sep 17 00:00:00 2001
From: Vitaly Chikunov <vt@altlinux.org>
Date: Sun, 20 Sep 2020 21:21:22 +0300
Subject: [PATCH] Compatibility with Solaris 10 (gcc 3.4.3)

Note, you will need to pass `-lsocket -lnsl` to the gcc for
socketpair(3SOCKET) to link `test_tls'.
---
 CMakeLists.txt          |  2 +-
 gost_grasshopper_math.h |  2 +-
 test_tls.c              | 20 +++++++++++++++-----
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b8891d..b7b7938 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,7 +14,7 @@ include_directories(${OPENSSL_INCLUDE_DIR})
 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
  add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Qunused-arguments -Wno-deprecated-declarations)
 elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
- add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Wno-error=unknown-pragmas -Wno-deprecated-declarations)
+ add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Wno-error=unknown-pragmas -Wno-error=pragmas -Wno-deprecated-declarations)
 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
diff --git a/gost_grasshopper_math.h b/gost_grasshopper_math.h
index 87d1265..91f276f 100644
--- a/gost_grasshopper_math.h
+++ b/gost_grasshopper_math.h
@@ -66,7 +66,7 @@ static GRASSHOPPER_INLINE void grasshopper_zero128(grasshopper_w128_t* x) {
 
 static GRASSHOPPER_INLINE void grasshopper_copy128(grasshopper_w128_t* to, const grasshopper_w128_t* from) {
 #if(GRASSHOPPER_BITS == 8 || GRASSHOPPER_BITS == 16)
-    __builtin_memcpy(&to, &from, sizeof(w128_t));
+    __builtin_memcpy(&to, &from, sizeof(grasshopper_w128_t));
 #else
 		int i;
     for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
diff --git a/test_tls.c b/test_tls.c
index bee5033..216fb2a 100644
--- a/test_tls.c
+++ b/test_tls.c
@@ -29,7 +29,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <err.h>
 
 /* For X509_NAME_add_entry_by_txt */
 #pragma GCC diagnostic ignored "-Wpointer-sign"
@@ -69,6 +68,17 @@ static const char *cipher_list;
 /* How much K to transfer between client and server. */
 #define KTRANSFER (1 * 1024)
 
+static void err(int eval, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vprintf(fmt, ap);
+    va_end(ap);
+    printf(": %s\n", strerror(errno));
+    exit(eval);
+}
+
 /*
  * Simple TLS Server code is based on
  * https://wiki.openssl.org/index.php/Simple_TLS_Server
@@ -274,7 +284,7 @@ int test(const char *algname, const char *paramset)
     ck = certgen(algname, paramset);
 
     int sockfd[2];
-    if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd) == -1)
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd) == -1)
 	err(1, "socketpair");
 
     setpgid(0, 0);
@@ -307,14 +317,14 @@ int test(const char *algname, const char *paramset)
     ret = (WIFEXITED(status) && WEXITSTATUS(status)) ||
 	(WIFSIGNALED(status) && WTERMSIG(status));
     if (ret) {
-	warnx(cRED "%s child %s with %d %s" cNORM,
+	fprintf(stderr, cRED "%s child %s with %d %s" cNORM,
 	    exited_pid == server_pid? "server" : "client",
 	    WIFSIGNALED(status)? "killed" : "exited",
 	    WIFSIGNALED(status)? WTERMSIG(status) : WEXITSTATUS(status),
 	    WIFSIGNALED(status)? strsignal(WTERMSIG(status)) : "");
 
 	/* If first child exited with error, kill other. */
-	warnx("terminating %s by force",
+	fprintf(stderr, "terminating %s by force",
 	    exited_pid == server_pid? "client" : "server");
 	kill(exited_pid == server_pid? client_pid : server_pid, SIGTERM);
     }
@@ -322,7 +332,7 @@ int test(const char *algname, const char *paramset)
     exited_pid = wait(&status);
     /* Report error unless we killed it. */
     if (!ret && (!WIFEXITED(status) || WEXITSTATUS(status)))
-	warnx(cRED "%s child %s with %d %s" cNORM,
+	fprintf(stderr, cRED "%s child %s with %d %s" cNORM,
 	    exited_pid == server_pid? "server" : "client",
 	    WIFSIGNALED(status)? "killed" : "exited",
 	    WIFSIGNALED(status)? WTERMSIG(status) : WEXITSTATUS(status),
-- 
2.39.5