Skip to content

Commit

Permalink
various fixes for Open Watcom build
Browse files Browse the repository at this point in the history
- fix build for OS/2
- fix build for Open Watcom 1.9
  • Loading branch information
jmalak committed Feb 25, 2025
1 parent 3557cc7 commit ddfbbc6
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 52 deletions.
7 changes: 5 additions & 2 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr
ret = ioctlsocket(sockfd, FIONBIO, &blocking);
if (ret == SOCKET_ERROR)
ret = WOLFSSL_FATAL_ERROR;
#elif defined(__WATCOMC__) && defined(__OS2__)
if (ioctl(sockfd, FIONBIO, &non_blocking) == -1)
ret = WOLFSSL_FATAL_ERROR;
#else
ret = fcntl(sockfd, F_GETFL, 0);
if (ret >= 0) {
Expand Down Expand Up @@ -1290,9 +1293,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr

ret = select(nfds, &rfds, &wfds, NULL, &timeout);
if (ret == 0) {
#ifdef DEBUG_HTTP
#ifdef DEBUG_HTTP
fprintf(stderr, "Timeout: %d\n", ret);
#endif
#endif
return HTTP_TIMEOUT;
}
else if (ret > 0) {
Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -14997,6 +14997,10 @@ void bench_sphincsKeySign(byte level, byte optim)
return (double)us / 1000000.0;
}

#elif defined(__WATCOMC__)

#include <time.h>
WC_INLINE double current_time(int reset) { (void)reset; return ((double)clock())/CLOCKS_PER_SEC; }
#else

#include <time.h>
Expand Down
55 changes: 51 additions & 4 deletions wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,50 @@
#endif /* HAVE_ECC */
#endif /*HAVE_PK_CALLBACKS */

#ifdef USE_WINDOWS_API
#ifdef __WATCOMC__
#define SNPRINTF snprintf
#if defined(__NT__)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
#include <wspiapi.h>
#endif
#define SOCKET_T SOCKET
#define XSLEEP_MS(t) Sleep(t)
#elif defined(__OS2__)
#include <netdb.h>
#include <sys/ioctl.h>
#include <tcpustd.h>
#define SOCKET_T int
#elif defined(__UNIX__)
#include <string.h>
#include <netdb.h>
#include <netinet/tcp.h>
#ifndef WOLFSSL_NDS
#include <sys/ioctl.h>
#endif
#include <time.h>
#include <sys/time.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
#define SOCKET_T int
#ifndef SO_NOSIGPIPE
#include <signal.h> /* ignore SIGPIPE */
#endif

#define XSLEEP_MS(m) \
{ \
struct timespec req = { (m)/1000, ((m) % 1000) * 1000 }; \
nanosleep( &req, NULL ); \
}
#endif
#elif defined(USE_WINDOWS_API)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
#include <ws2tcpip.h>
#include <wspiapi.h>
#endif
#define SOCKET_T SOCKET
Expand Down Expand Up @@ -1429,7 +1468,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)
err_sys_with_errno("socket failed\n");
}

#ifndef USE_WINDOWS_API
#if !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && !defined(__OS2__)
#ifdef SO_NOSIGPIPE
{
int on = 1;
Expand Down Expand Up @@ -1457,7 +1496,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp)
err_sys_with_errno("setsockopt TCP_NODELAY failed\n");
}
#endif
#endif /* USE_WINDOWS_API */
#endif /* !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && !defined(__OS2__) */
}

#if defined(WOLFSSL_WOLFSENTRY_HOOKS) && defined(WOLFSENTRY_H)
Expand Down Expand Up @@ -1801,6 +1840,10 @@ static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd)
|| defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
|| defined(WOLFSSL_ZEPHYR)
/* non blocking not supported, for now */
#elif defined(__WATCOMC__) && defined(__OS2__)
int blocking = 1;
if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
err_sys_with_errno("ioctl failed");
#else
int flags = fcntl(*sockfd, F_GETFL, 0);
if (flags < 0)
Expand All @@ -1822,6 +1865,10 @@ static WC_INLINE void tcp_set_blocking(SOCKET_T* sockfd)
|| defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \
|| defined(WOLFSSL_ZEPHYR)
/* non blocking not supported, for now */
#elif defined(__WATCOMC__) && defined(__OS2__)
int blocking = 0;
if (ioctl(*sockfd, FIONBIO, &blocking) == -1)
err_sys_with_errno("ioctl failed");
#else
int flags = fcntl(*sockfd, F_GETFL, 0);
if (flags < 0)
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ typedef byte ecc_oid_t;
#endif


#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API)
#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API) && !defined(__WATCOMC__)
/* MSC does something different with the pointers to the arrays than GCC,
* and it causes the FIPS checksum to fail. In the case of windows builds,
* store everything as arrays instead of pointers to strings. */
Expand Down
8 changes: 8 additions & 0 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,13 @@ typedef struct w64wrapper {
/* use only Thread Safe version of strtok */
#if defined(USE_WOLF_STRTOK)
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
#elif defined(__WATCOMC__)
#if __WATCOMC__ < 1300
#define USE_WOLF_STRTOK
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
#else
#define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr))
#endif
#elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS)
#define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr))
#else
Expand Down Expand Up @@ -1503,6 +1510,7 @@ typedef struct w64wrapper {
#define WOLFSSL_THREAD __stdcall
#define WOLFSSL_THREAD_NO_JOIN _WCCALLBACK
#elif defined(__OS2__)
#define WOLFSSL_THREAD_VOID_RETURN
typedef void THREAD_RETURN;
typedef TID THREAD_TYPE;
typedef struct COND_TYPE {
Expand Down
9 changes: 8 additions & 1 deletion wolfssl/wolfcrypt/visibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@
#define WOLFSSL_LOCAL
#endif /* HAVE_VISIBILITY */
#else /* BUILDING_WOLFSSL */
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \
#if defined(__WATCOMC__)
#if defined(WOLFSSL_DLL) && defined(__NT__)
#define WOLFSSL_API __declspec(dllimport)
#else
#define WOLFSSL_API
#endif
#define WOLFSSL_LOCAL
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \
defined(_WIN32_WCE) || defined(__WATCOMC__)
#if defined(WOLFSSL_DLL)
#define WOLFSSL_API __declspec(dllimport)
Expand Down
56 changes: 40 additions & 16 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,31 @@
#endif

/* THREADING/MUTEX SECTION */
#if defined(__WATCOMC__)
#if !defined(SINGLE_THREADED)
#if defined(SINGLE_THREADED) && defined(NO_FILESYSTEM)
/* No system headers required for build. */
#elif defined(__WATCOMC__)
#if defined(SINGLE_THREADED)
#if defined(USE_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#ifndef WOLFSSL_USER_IO
#include <winsock2.h>
#include <ws2tcpip.h> /* required for InetPton */
#endif
#elif defined(__OS2__)
#include <os2.h>
#endif
#else
#if defined(USE_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#include <process.h>
#ifndef WOLFSSL_USER_IO
#include <winsock2.h>
#include <ws2tcpip.h> /* required for InetPton */
#endif
#elif defined(__OS2__)
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
Expand All @@ -140,17 +158,7 @@
#include <pthread.h>
#endif
#endif
#else
#if defined(USE_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#elif defined(__OS2__)
#include <os2.h>
#endif
#endif
#elif defined(SINGLE_THREADED) && defined(NO_FILESYSTEM)
/* No system headers required for build. */
#elif defined(USE_WINDOWS_API)
#if defined(WOLFSSL_PTHREADS)
#include <pthread.h>
Expand Down Expand Up @@ -926,7 +934,25 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);

#if !defined(NO_WOLFSSL_DIR)\
&& !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
#if defined(USE_WINDOWS_API)
#if defined(__WATCOMC__)
#include <unistd.h>
#include <sys/stat.h>
#define XWRITE write
#define XREAD read
#define XCLOSE close
#define XSTAT stat
#define XS_ISREG(s) S_ISREG(s)
#if defined(__UNIX__)
#include <dirent.h>
#define SEPARATOR_CHAR ':'
#else
#include <direct.h>
#define SEPARATOR_CHAR ';'
#endif
#if defined(__NT__)
#define XALTHOMEVARNAME "USERPROFILE"
#endif
#elif defined(USE_WINDOWS_API)
#include <io.h>
#include <sys/stat.h>
#ifndef XSTAT
Expand Down Expand Up @@ -964,9 +990,7 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
#define SEPARATOR_CHAR ':'

#else
#ifndef NO_WOLFSSL_DIR
#include <dirent.h>
#endif
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#define XWRITE write
Expand Down
Loading

0 comments on commit ddfbbc6

Please sign in to comment.