Skip to content

Commit a0d6afb

Browse files
authored
Merge pull request #8505 from jmalak/ow-fixes
various fixes for Open Watcom build
2 parents 183d9b4 + b5ba7a6 commit a0d6afb

10 files changed

Lines changed: 212 additions & 57 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ __SUNPRO_CC
947947
__SVR4
948948
__TI_COMPILER_VERSION__
949949
__TURBOC__
950+
__UNIX__
950951
__USE_GNU
951952
__USE_MISC
952953
__USE_XOPEN2K

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,12 +2427,15 @@ target_include_directories(wolfssl
24272427

24282428
target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS})
24292429

2430-
if (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_SYSTEM_NAME} MATCHES "^MINGW")
2430+
if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
2431+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2432+
target_link_libraries(wolfssl PUBLIC ws2_32 crypt32)
2433+
endif()
2434+
elseif (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_SYSTEM_NAME} MATCHES "^MINGW")
24312435
# For Windows link required libraries
24322436
message("Building on Windows/MSYS/MINGW")
24332437
target_link_libraries(wolfssl PUBLIC
24342438
ws2_32 crypt32 advapi32)
2435-
elseif(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
24362439
elseif(APPLE)
24372440
message("Building on Apple")
24382441
if(WOLFSSL_SYS_CA_CERTS)

src/wolfio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr
12511251
ret = ioctlsocket(sockfd, FIONBIO, &blocking);
12521252
if (ret == SOCKET_ERROR)
12531253
ret = WOLFSSL_FATAL_ERROR;
1254+
#elif defined(__WATCOMC__) && defined(__OS2__)
1255+
if (ioctl(sockfd, FIONBIO, &non_blocking) == -1)
1256+
ret = WOLFSSL_FATAL_ERROR;
12541257
#else
12551258
ret = fcntl(sockfd, F_GETFL, 0);
12561259
if (ret >= 0) {
@@ -1290,9 +1293,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr
12901293

12911294
ret = select(nfds, &rfds, &wfds, NULL, &timeout);
12921295
if (ret == 0) {
1293-
#ifdef DEBUG_HTTP
1296+
#ifdef DEBUG_HTTP
12941297
fprintf(stderr, "Timeout: %d\n", ret);
1295-
#endif
1298+
#endif
12961299
return HTTP_TIMEOUT;
12971300
}
12981301
else if (ret > 0) {

wolfcrypt/benchmark/benchmark.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14997,6 +14997,14 @@ void bench_sphincsKeySign(byte level, byte optim)
1499714997
return (double)us / 1000000.0;
1499814998
}
1499914999

15000+
#elif defined(__WATCOMC__)
15001+
15002+
#include <time.h>
15003+
WC_INLINE double current_time(int reset)
15004+
{
15005+
(void)reset;
15006+
return ((double)clock())/CLOCKS_PER_SEC;
15007+
}
1500015008
#else
1500115009

1500215010
#include <time.h>

wolfssl/test.h

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,50 @@
8585
#endif /* HAVE_ECC */
8686
#endif /*HAVE_PK_CALLBACKS */
8787

88-
#ifdef USE_WINDOWS_API
88+
#ifdef __WATCOMC__
89+
#define SNPRINTF snprintf
90+
#if defined(__NT__)
91+
#include <winsock2.h>
92+
#include <ws2tcpip.h>
93+
#include <process.h>
94+
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
95+
#include <wspiapi.h>
96+
#endif
97+
#define SOCKET_T SOCKET
98+
#define XSLEEP_MS(t) Sleep(t)
99+
#elif defined(__OS2__)
100+
#include <netdb.h>
101+
#include <sys/ioctl.h>
102+
#include <tcpustd.h>
103+
#define SOCKET_T int
104+
#elif defined(__UNIX__)
105+
#include <string.h>
106+
#include <netdb.h>
107+
#include <netinet/tcp.h>
108+
#ifndef WOLFSSL_NDS
109+
#include <sys/ioctl.h>
110+
#endif
111+
#include <time.h>
112+
#include <sys/time.h>
113+
#ifdef HAVE_PTHREAD
114+
#include <pthread.h>
115+
#endif
116+
#define SOCKET_T int
117+
#ifndef SO_NOSIGPIPE
118+
#include <signal.h> /* ignore SIGPIPE */
119+
#endif
120+
121+
#define XSLEEP_MS(m) \
122+
{ \
123+
struct timespec req = { (m)/1000, ((m) % 1000) * 1000 }; \
124+
nanosleep( &req, NULL ); \
125+
}
126+
#endif
127+
#elif defined(USE_WINDOWS_API)
89128
#include <winsock2.h>
129+
#include <ws2tcpip.h>
90130
#include <process.h>
91131
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
92-
#include <ws2tcpip.h>
93132
#include <wspiapi.h>
94133
#endif
95134
#define SOCKET_T SOCKET
@@ -1429,7 +1468,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)
14291468
err_sys_with_errno("socket failed\n");
14301469
}
14311470

1432-
#ifndef USE_WINDOWS_API
1471+
#if !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && !defined(__OS2__)
14331472
#ifdef SO_NOSIGPIPE
14341473
{
14351474
int on = 1;
@@ -1457,7 +1496,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)
14571496
err_sys_with_errno("setsockopt TCP_NODELAY failed\n");
14581497
}
14591498
#endif
1460-
#endif /* USE_WINDOWS_API */
1499+
#endif /* !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && ... */
14611500
}
14621501

14631502
#if defined(WOLFSSL_WOLFSENTRY_HOOKS) && defined(WOLFSENTRY_H)
@@ -1801,6 +1840,10 @@ static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)
18011840
|| defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
18021841
|| defined(WOLFSSL_ZEPHYR)
18031842
/* non blocking not supported, for now */
1843+
#elif defined(__WATCOMC__) && defined(__OS2__)
1844+
int blocking = 1;
1845+
if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
1846+
err_sys_with_errno("ioctl failed");
18041847
#else
18051848
int flags = fcntl(*sockfd, F_GETFL, 0);
18061849
if (flags < 0)
@@ -1822,6 +1865,10 @@ static WC_INLINE void tcp_set_blocking(SOCKET_T* sockfd)
18221865
|| defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
18231866
|| defined(WOLFSSL_ZEPHYR)
18241867
/* non blocking not supported, for now */
1868+
#elif defined(__WATCOMC__) && defined(__OS2__)
1869+
int blocking = 0;
1870+
if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
1871+
err_sys_with_errno("ioctl failed");
18251872
#else
18261873
int flags = fcntl(*sockfd, F_GETFL, 0);
18271874
if (flags < 0)

wolfssl/wolfcrypt/ecc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ typedef byte ecc_oid_t;
287287
#endif
288288

289289

290-
#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API)
290+
#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API) && \
291+
!defined(__WATCOMC__)
291292
/* MSC does something different with the pointers to the arrays than GCC,
292293
* and it causes the FIPS checksum to fail. In the case of windows builds,
293294
* store everything as arrays instead of pointers to strings. */

wolfssl/wolfcrypt/types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,13 @@ typedef struct w64wrapper {
922922
/* use only Thread Safe version of strtok */
923923
#if defined(USE_WOLF_STRTOK)
924924
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
925+
#elif defined(__WATCOMC__)
926+
#if __WATCOMC__ < 1300
927+
#define USE_WOLF_STRTOK
928+
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
929+
#else
930+
#define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
931+
#endif
925932
#elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
926933
#define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
927934
#else
@@ -1503,6 +1510,7 @@ typedef struct w64wrapper {
15031510
#define WOLFSSL_THREAD __stdcall
15041511
#define WOLFSSL_THREAD_NO_JOIN _WCCALLBACK
15051512
#elif defined(__OS2__)
1513+
#define WOLFSSL_THREAD_VOID_RETURN
15061514
typedef void THREAD_RETURN;
15071515
typedef TID THREAD_TYPE;
15081516
typedef struct COND_TYPE {

wolfssl/wolfcrypt/visibility.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@
5151
#define WOLFSSL_LOCAL
5252
#endif /* HAVE_VISIBILITY */
5353
#else /* BUILDING_WOLFSSL */
54-
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \
55-
defined(_WIN32_WCE) || defined(__WATCOMC__)
54+
#if defined(__WATCOMC__)
55+
#if defined(WOLFSSL_DLL) && defined(__NT__)
56+
#define WOLFSSL_API __declspec(dllimport)
57+
#else
58+
#define WOLFSSL_API
59+
#endif
60+
#define WOLFSSL_LOCAL
61+
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \
62+
defined(_WIN32_WCE)
5663
#if defined(WOLFSSL_DLL)
5764
#define WOLFSSL_API __declspec(dllimport)
5865
#else

wolfssl/wolfcrypt/wc_port.h

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,31 @@
120120
#endif
121121

122122
/* THREADING/MUTEX SECTION */
123-
#if defined(__WATCOMC__)
124-
#if !defined(SINGLE_THREADED)
123+
#if defined(SINGLE_THREADED) && defined(NO_FILESYSTEM)
124+
/* No system headers required for build. */
125+
#elif defined(__WATCOMC__)
126+
#if defined(SINGLE_THREADED)
125127
#if defined(USE_WINDOWS_API)
126128
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
127129
#include <windows.h>
128-
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
130+
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
131+
#ifndef WOLFSSL_USER_IO
132+
#include <winsock2.h>
133+
#include <ws2tcpip.h> /* required for InetPton */
134+
#endif
135+
#elif defined(__OS2__)
136+
#include <os2.h>
137+
#endif
138+
#else
139+
#if defined(USE_WINDOWS_API)
140+
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
141+
#include <windows.h>
142+
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
129143
#include <process.h>
144+
#ifndef WOLFSSL_USER_IO
145+
#include <winsock2.h>
146+
#include <ws2tcpip.h> /* required for InetPton */
147+
#endif
130148
#elif defined(__OS2__)
131149
#define INCL_DOSSEMAPHORES
132150
#define INCL_DOSPROCESS
@@ -140,17 +158,7 @@
140158
#include <pthread.h>
141159
#endif
142160
#endif
143-
#else
144-
#if defined(USE_WINDOWS_API)
145-
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
146-
#include <windows.h>
147-
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
148-
#elif defined(__OS2__)
149-
#include <os2.h>
150-
#endif
151161
#endif
152-
#elif defined(SINGLE_THREADED) && defined(NO_FILESYSTEM)
153-
/* No system headers required for build. */
154162
#elif defined(USE_WINDOWS_API)
155163
#if defined(WOLFSSL_PTHREADS)
156164
#include <pthread.h>
@@ -164,7 +172,7 @@
164172
#if !defined(WOLFSSL_SGX) && !defined(WOLFSSL_NOT_WINDOWS_API)
165173
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file. */
166174
#include <windows.h>
167-
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
175+
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
168176
#ifndef WOLFSSL_USER_IO
169177
#include <winsock2.h>
170178
#include <ws2tcpip.h> /* required for InetPton */
@@ -926,7 +934,25 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
926934

927935
#if !defined(NO_WOLFSSL_DIR)\
928936
&& !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
929-
#if defined(USE_WINDOWS_API)
937+
#if defined(__WATCOMC__)
938+
#include <unistd.h>
939+
#include <sys/stat.h>
940+
#define XWRITE write
941+
#define XREAD read
942+
#define XCLOSE close
943+
#define XSTAT stat
944+
#define XS_ISREG(s) S_ISREG(s)
945+
#if defined(__UNIX__)
946+
#include <dirent.h>
947+
#define SEPARATOR_CHAR ':'
948+
#else
949+
#include <direct.h>
950+
#define SEPARATOR_CHAR ';'
951+
#endif
952+
#if defined(__NT__)
953+
#define XALTHOMEVARNAME "USERPROFILE"
954+
#endif
955+
#elif defined(USE_WINDOWS_API)
930956
#include <io.h>
931957
#include <sys/stat.h>
932958
#ifndef XSTAT
@@ -964,9 +990,7 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
964990
#define SEPARATOR_CHAR ':'
965991

966992
#else
967-
#ifndef NO_WOLFSSL_DIR
968-
#include <dirent.h>
969-
#endif
993+
#include <dirent.h>
970994
#include <unistd.h>
971995
#include <sys/stat.h>
972996
#define XWRITE write

0 commit comments

Comments
 (0)