cleaned up some code
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
hyung-hwan 2023-12-07 23:01:17 +09:00
parent af3abee6ca
commit 10189e60ce
9 changed files with 513 additions and 25 deletions

View File

@ -24,6 +24,10 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#if defined(_WIN32)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <hcl.h> #include <hcl.h>
#include <hcl-utl.h> #include <hcl-utl.h>
#include <hcl-opt.h> #include <hcl-opt.h>
@ -343,7 +347,13 @@ static void set_signal_to_default (int sig)
static void print_info (void) static void print_info (void)
{ {
#if defined(HCL_CONFIGURE_CMD) && defined(HCL_CONFIGURE_ARGS)
printf ("Configured with: %s %s\n", HCL_CONFIGURE_CMD, HCL_CONFIGURE_ARGS); printf ("Configured with: %s %s\n", HCL_CONFIGURE_CMD, HCL_CONFIGURE_ARGS);
#elif defined(_WIN32)
printf("Built for windows\n");
#else
/* TODO: improve this part */
#endif
} }
static void print_synerr (hcl_t* hcl) static void print_synerr (hcl_t* hcl)
@ -361,7 +371,7 @@ static void print_synerr (hcl_t* hcl)
} }
else else
{ {
hcl_logbfmt (hcl, HCL_LOG_STDERR, "%s", xtn->cci_path); hcl_logbfmt (hcl, HCL_LOG_STDERR, "%hs", xtn->cci_path);
} }
hcl_logbfmt (hcl, HCL_LOG_STDERR, "[%zu,%zu] %js", hcl_logbfmt (hcl, HCL_LOG_STDERR, "[%zu,%zu] %js",
@ -465,14 +475,27 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
FILE* fp = HCL_NULL; FILE* fp = HCL_NULL;
int is_tty; int is_tty;
#if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)
errno_t err = fopen_s(&fp, xtn->cci_path, FOPEN_R_FLAGS);
if (err != 0)
{
hcl_logbfmt(hcl, HCL_LOG_STDERR, "ERROR: failed to open - %hs - %hs\n", xtn->cci_path, strerror(err));
goto oops;
}
#else
fp = fopen(xtn->cci_path, FOPEN_R_FLAGS); fp = fopen(xtn->cci_path, FOPEN_R_FLAGS);
if (!fp) if (!fp)
{ {
hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: failed to open - %hs - %hs\n", xtn->cci_path, strerror(errno)); hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: failed to open - %hs - %hs\n", xtn->cci_path, strerror(errno));
goto oops; goto oops;
} }
#endif
#if defined(_WIN32)
is_tty = _isatty(_fileno(fp));
#else
is_tty = isatty(fileno(fp)); is_tty = isatty(fileno(fp));
#endif
/* override the default cnode handler. the default one simply /* override the default cnode handler. the default one simply
* compiles the expression node without execution */ * compiles the expression node without execution */
@ -486,7 +509,6 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
/* [NOTE] it isn't a very nice idea to get this internal data and use it with read_input() */ /* [NOTE] it isn't a very nice idea to get this internal data and use it with read_input() */
while (1) while (1)
{ {
if (is_tty) if (is_tty)
{ {
hcl_bch_t bch; hcl_bch_t bch;

View File

@ -2110,10 +2110,7 @@ static int compile_expression_block (hcl_t* hcl, hcl_cnode_t* src, const hcl_bch
static int compile_do (hcl_t* hcl, hcl_cnode_t* xlist) static int compile_do (hcl_t* hcl, hcl_cnode_t* xlist)
{ {
hcl_cnode_t* cmd, * obj, * tmp; hcl_cnode_t* cmd, * obj;
hcl_oow_t nlvars, tvslen;
hcl_fnblk_info_t* fbi;
hcl_cframe_t* cf;
int flags = 0; int flags = 0;
/* (do /* (do

View File

@ -58,7 +58,7 @@ static struct
{ 3, { 's','e','t' }, HCL_SYNCODE_SET, HCL_OFFSETOF(hcl_t,_set) }, { 3, { 's','e','t' }, HCL_SYNCODE_SET, HCL_OFFSETOF(hcl_t,_set) },
{ 5, { 's','e','t','-','r' }, HCL_SYNCODE_SET_R, HCL_OFFSETOF(hcl_t,_set_r) }, { 5, { 's','e','t','-','r' }, HCL_SYNCODE_SET_R, HCL_OFFSETOF(hcl_t,_set_r) },
{ 5, { 't','h','r','o','w' }, HCL_SYNCODE_THROW, HCL_OFFSETOF(hcl_t,_throw) }, { 5, { 't','h','r','o','w' }, HCL_SYNCODE_THROW, HCL_OFFSETOF(hcl_t,_throw) },
{ 3, { 't','r','y' }, HCL_SYNCODE_TRY, HCL_OFFSETOF(hcl_t,_try) }, { 3, { 't','r','y' }, HCL_SYNCODE_TRY, HCL_OFFSETOF(hcl_t,_try_) },
{ 5, { 'u','n','t','i','l' }, HCL_SYNCODE_UNTIL, HCL_OFFSETOF(hcl_t,_until) }, { 5, { 'u','n','t','i','l' }, HCL_SYNCODE_UNTIL, HCL_OFFSETOF(hcl_t,_until) },
{ 5, { 'w','h','i','l','e' }, HCL_SYNCODE_WHILE, HCL_OFFSETOF(hcl_t,_while) } { 5, { 'w','h','i','l','e' }, HCL_SYNCODE_WHILE, HCL_OFFSETOF(hcl_t,_while) }
}; };

View File

@ -40,6 +40,7 @@ _M_X64 x64 platform
/* windows for most of non-x86 platforms dropped. /* windows for most of non-x86 platforms dropped.
* make it selective to support old non-x86 windows platforms. */ * make it selective to support old non-x86 windows platforms. */
#define HCL_ENDIAN_LITTLE #define HCL_ENDIAN_LITTLE
#define HCL_ENABLE_WIDE_CHAR
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
# define HCL_SIZEOF_CHAR 1 # define HCL_SIZEOF_CHAR 1

View File

@ -1614,7 +1614,7 @@ struct hcl_t
hcl_oop_t _set; /* symbol */ hcl_oop_t _set; /* symbol */
hcl_oop_t _set_r; /* symbol */ hcl_oop_t _set_r; /* symbol */
hcl_oop_t _throw; /* symbol */ hcl_oop_t _throw; /* symbol */
hcl_oop_t _try; /* symbol */ hcl_oop_t _try_; /* symbol */ /* _try is special in MSVC. */
hcl_oop_t _until; /* symbol */ hcl_oop_t _until; /* symbol */
hcl_oop_t _while; /* symbol */ hcl_oop_t _while; /* symbol */

412
lib/poll-msw.c Normal file
View File

@ -0,0 +1,412 @@
/* Emulation for poll(2)
Contributed by Paolo Bonzini.
Copyright 2001-2003, 2006-2016 Free Software Foundation, Inc.
This file is part of gnulib.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
/* Tell gcc not to warn about the (nfd < 0) tests, below. */
#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include "poll-msw.h"
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#if defined(__BORLANDC__)
# include <malloc.h>
# define _alloca alloca
#endif
#ifndef INFTIM
# define INFTIM (-1)
#endif
/* BeOS does not have MSG_PEEK. */
#ifndef MSG_PEEK
# define MSG_PEEK 0
#endif
#ifndef POLLRDNORM
# define POLLRDNORM 0
# define POLLRDBAND 0
# define POLLWRNORM 0
# define POLLWRBAND 0
#endif
static BOOL IsConsoleHandle (HANDLE h)
{
DWORD mode;
return GetConsoleMode (h, &mode) != 0;
}
static BOOL IsSocketHandle (HANDLE h)
{
WSANETWORKEVENTS ev;
if (IsConsoleHandle (h)) return FALSE;
/* Under Wine, it seems that getsockopt returns 0 for pipes too.
WSAEnumNetworkEvents instead distinguishes the two correctly. */
ev.lNetworkEvents = 0xDEADBEEF;
WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
return ev.lNetworkEvents != 0xDEADBEEF;
}
/* Declare data structures for ntdll functions. */
typedef struct _FILE_PIPE_LOCAL_INFORMATION
{
ULONG NamedPipeType;
ULONG NamedPipeConfiguration;
ULONG MaximumInstances;
ULONG CurrentInstances;
ULONG InboundQuota;
ULONG ReadDataAvailable;
ULONG OutboundQuota;
ULONG WriteQuotaAvailable;
ULONG NamedPipeState;
ULONG NamedPipeEnd;
} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
typedef struct _IO_STATUS_BLOCK
{
union
{
DWORD Status;
PVOID Pointer;
} u;
/*ULONG_PTR Information;*/
ULONG* Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef enum _FILE_INFORMATION_CLASS
{
FilePipeLocalInformation = 24
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
typedef DWORD (WINAPI *PNtQueryInformationFile) (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS);
# ifndef PIPE_BUF
# define PIPE_BUF 512
# endif
/* Compute revents values for file handle H. If some events cannot happen
for the handle, eliminate them from *P_SOUGHT. */
static int windows_compute_revents (HANDLE h, int *p_sought)
{
int i, ret, happened;
INPUT_RECORD *irbuffer;
DWORD avail, nbuffer;
BOOL bRet;
IO_STATUS_BLOCK iosb;
FILE_PIPE_LOCAL_INFORMATION fpli;
static PNtQueryInformationFile NtQueryInformationFile;
static BOOL once_only;
switch (GetFileType (h))
{
case FILE_TYPE_PIPE:
if (!once_only)
{
NtQueryInformationFile = (PNtQueryInformationFile)
GetProcAddress (GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationFile");
once_only = TRUE;
}
happened = 0;
if (PeekNamedPipe(h, NULL, 0, NULL, &avail, NULL) != 0)
{
if (avail)
happened |= *p_sought & (POLLIN | POLLRDNORM);
}
else if (GetLastError () == ERROR_BROKEN_PIPE)
happened |= POLLHUP;
else
{
/* It was the write-end of the pipe. Check if it is writable.
If NtQueryInformationFile fails, optimistically assume the pipe is
writable. This could happen on Windows 9x, where
NtQueryInformationFile is not available, or if we inherit a pipe
that doesn't permit FILE_READ_ATTRIBUTES access on the write end
(I think this should not happen since Windows XP SP2; WINE seems
fine too). Otherwise, ensure that enough space is available for
atomic writes. */
memset (&iosb, 0, sizeof (iosb));
memset (&fpli, 0, sizeof (fpli));
if (!NtQueryInformationFile
|| NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), FilePipeLocalInformation)
|| fpli.WriteQuotaAvailable >= PIPE_BUF
|| (fpli.OutboundQuota < PIPE_BUF && fpli.WriteQuotaAvailable == fpli.OutboundQuota))
{
happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
}
}
return happened;
case FILE_TYPE_CHAR:
ret = WaitForSingleObject (h, 0);
if (!IsConsoleHandle (h))
return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0;
nbuffer = avail = 0;
bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
if (bRet)
{
/* Input buffer. */
*p_sought &= POLLIN | POLLRDNORM;
if (nbuffer == 0)
return POLLHUP;
if (!*p_sought)
return 0;
irbuffer = (INPUT_RECORD *)_alloca(nbuffer * sizeof (INPUT_RECORD));
bRet = PeekConsoleInput(h, irbuffer, nbuffer, &avail);
if (!bRet || avail == 0)
return POLLHUP;
for (i = 0; i < avail; i++)
if (irbuffer[i].EventType == KEY_EVENT)
return *p_sought;
return 0;
}
else
{
/* Screen buffer. */
*p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND;
return *p_sought;
}
default:
ret = WaitForSingleObject (h, 0);
if (ret == WAIT_OBJECT_0)
return *p_sought & ~(POLLPRI | POLLRDBAND);
return *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
}
}
/* Convert fd_sets returned by select into revents values. */
static int windows_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
{
int happened = 0;
if ((lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) == FD_ACCEPT)
happened |= (POLLIN | POLLRDNORM) & sought;
else if (lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
{
int r, error;
char data[64];
WSASetLastError (0);
r = recv (h, data, sizeof (data), MSG_PEEK);
error = WSAGetLastError ();
WSASetLastError (0);
if (r > 0 || error == WSAENOTCONN)
happened |= (POLLIN | POLLRDNORM) & sought;
/* Distinguish hung-up sockets from other errors. */
else if (r == 0 || error == WSAESHUTDOWN || error == WSAECONNRESET
|| error == WSAECONNABORTED || error == WSAENETRESET)
happened |= POLLHUP;
else
happened |= POLLERR;
}
if (lNetworkEvents & (FD_WRITE | FD_CONNECT))
happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought;
if (lNetworkEvents & FD_OOB)
happened |= (POLLPRI | POLLRDBAND) & sought;
return happened;
}
int poll (struct pollfd *pfd, nfds_t nfd, int timeout)
{
static struct timeval tv0;
static HANDLE hEvent;
WSANETWORKEVENTS ev;
HANDLE h, handle_array[FD_SETSIZE + 2];
DWORD ret, wait_timeout, nhandles;
fd_set rfds, wfds, xfds;
BOOL poll_again;
MSG msg;
int rc = 0;
nfds_t i;
if (nfd < 0 || timeout < -1)
{
errno = EINVAL;
return -1;
}
if (!hEvent)
hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
restart:
handle_array[0] = hEvent;
nhandles = 1;
FD_ZERO (&rfds);
FD_ZERO (&wfds);
FD_ZERO (&xfds);
/* Classify socket handles and create fd sets. */
for (i = 0; i < nfd; i++)
{
int sought = pfd[i].events;
pfd[i].revents = 0;
if (pfd[i].fd < 0) continue;
if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND | POLLPRI | POLLRDBAND))) continue;
h = (HANDLE)_get_osfhandle(pfd[i].fd);
if (IsSocketHandle (h))
{
int requested = FD_CLOSE;
/* see above; socket handles are mapped onto select. */
if (sought & (POLLIN | POLLRDNORM))
{
requested |= FD_READ | FD_ACCEPT;
FD_SET ((SOCKET) h, &rfds);
}
if (sought & (POLLOUT | POLLWRNORM | POLLWRBAND))
{
requested |= FD_WRITE | FD_CONNECT;
FD_SET ((SOCKET) h, &wfds);
}
if (sought & (POLLPRI | POLLRDBAND))
{
requested |= FD_OOB;
FD_SET ((SOCKET) h, &xfds);
}
if (requested)
WSAEventSelect ((SOCKET) h, hEvent, requested);
}
else
{
/* Poll now. If we get an event, do not poll again. Also,
screen buffer handles are waitable, and they'll block until
a character is available. windows_compute_revents eliminates
bits for the "wrong" direction. */
pfd[i].revents = windows_compute_revents (h, &sought);
if (sought) handle_array[nhandles++] = h;
if (pfd[i].revents) timeout = 0;
}
}
if (select(0, &rfds, &wfds, &xfds, &tv0) > 0)
{
/* Do MsgWaitForMultipleObjects anyway to dispatch messages, but
no need to call select again. */
poll_again = FALSE;
wait_timeout = 0;
}
else
{
poll_again = TRUE;
if (timeout == INFTIM)
wait_timeout = INFINITE;
else
wait_timeout = timeout;
}
for (;;)
{
ret = MsgWaitForMultipleObjects(nhandles, handle_array, FALSE, wait_timeout, QS_ALLINPUT);
if (ret == WAIT_OBJECT_0 + nhandles)
{
/* new input of some other kind */
BOOL bRet;
while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
break;
}
if (poll_again)
select (0, &rfds, &wfds, &xfds, &tv0);
/* Place a sentinel at the end of the array. */
handle_array[nhandles] = NULL;
nhandles = 1;
for (i = 0; i < nfd; i++)
{
int happened;
if (pfd[i].fd < 0)
continue;
if (!(pfd[i].events & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND)))
continue;
h = (HANDLE) _get_osfhandle (pfd[i].fd);
if (h != handle_array[nhandles])
{
/* It's a socket. */
WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
WSAEventSelect ((SOCKET) h, 0, 0);
/* If we're lucky, WSAEnumNetworkEvents already provided a way
to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */
if (FD_ISSET ((SOCKET) h, &rfds) && !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT)))
ev.lNetworkEvents |= FD_READ | FD_ACCEPT;
if (FD_ISSET ((SOCKET) h, &wfds))
ev.lNetworkEvents |= FD_WRITE | FD_CONNECT;
if (FD_ISSET ((SOCKET) h, &xfds))
ev.lNetworkEvents |= FD_OOB;
happened = windows_compute_revents_socket ((SOCKET) h, pfd[i].events, ev.lNetworkEvents);
}
else
{
/* Not a socket. */
int sought = pfd[i].events;
happened = windows_compute_revents (h, &sought);
nhandles++;
}
if ((pfd[i].revents |= happened) != 0) rc++;
}
if (!rc && timeout == INFTIM)
{
SleepEx (1, TRUE);
goto restart;
}
return rc;
}

49
lib/poll-msw.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef _POLL_MSW_H_
#define _POLL_MSW_H_
#include <hcl.h>
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
/* Event types that can be polled for. These bits may be set in `events'
to indicate the interesting event types; they will appear in `revents'
to indicate the status of the file descriptor. */
#define POLLIN 0x001 /* There is data to read. */
#define POLLPRI 0x002 /* There is urgent data to read. */
#define POLLOUT 0x004 /* Writing now will not block. */
/* Event types always implicitly polled for. These bits need not be set in
`events', but they will appear in `revents' to indicate the status of
the file descriptor. */
#define POLLERR 0x008 /* Error condition. */
#define POLLHUP 0x010 /* Hung up. */
#define POLLNVAL 0x020 /* Invalid polling request. */
/* Data structure describing a polling request. */
struct pollfd
{
int fd; /* File descriptor to poll. */
short int events; /* Types of events poller cares about. */
short int revents; /* Types of events that actually occurred. */
};
/* Poll the file descriptors described by the NFDS structures starting at
FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for
an event to occur; if TIMEOUT is -1, block until an event occurs.
Returns the number of file descriptors with events, zero if timed out,
or -1 for errors. */
#endif
typedef unsigned long nfds_t;
#if defined(__cplusplus)
extern "C" {
#endif
int poll (struct pollfd *pfd, nfds_t nfd, int timeout);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -2637,6 +2637,7 @@ int hcl_feeduchars (hcl_t* hcl, const hcl_uch_t* data, hcl_oow_t len)
#else #else
hcl_bch_t outbuf[HCL_BCSIZE_MAX * 128]; hcl_bch_t outbuf[HCL_BCSIZE_MAX * 128];
hcl_oow_t inlen, outlen, inpos; hcl_oow_t inlen, outlen, inpos;
int n;
inpos = 0; inpos = 0;
while (len > 0) while (len > 0)
@ -2647,7 +2648,7 @@ int hcl_feeduchars (hcl_t* hcl, const hcl_uch_t* data, hcl_oow_t len)
if (outlen > 0 && hcl_feed(hcl, outbuf, outlen) <= -1) return -1; if (outlen > 0 && hcl_feed(hcl, outbuf, outlen) <= -1) return -1;
inpos += inlen; inpos += inlen;
len -= inlen; len -= inlen;
if (n <= -1) return -1 if (n <= -1) return -1;
} }
return 0; return 0;
#endif #endif

View File

@ -34,9 +34,12 @@
#include <string.h> #include <string.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h> # include <windows.h>
# include <tchar.h> # include <tchar.h>
# include <time.h> # include <time.h>
# include <fcntl.h>
# include <io.h> # include <io.h>
# include <errno.h> # include <errno.h>
@ -537,12 +540,10 @@ static void flush_log (hcl_t* hcl, int fd)
} }
} }
static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len) static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{ {
hcl_bch_t buf[256]; hcl_bch_t buf[256];
hcl_oow_t ucslen, bcslen, msgidx; hcl_oow_t msgidx;
int n;
xtn_t* xtn = GET_XTN(hcl); xtn_t* xtn = GET_XTN(hcl);
int logfd; int logfd;
@ -626,6 +627,9 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
msgidx = 0; msgidx = 0;
while (len > 0) while (len > 0)
{ {
hcl_oow_t ucslen, bcslen;
int n;
ucslen = len; ucslen = len;
bcslen = HCL_COUNTOF(buf); bcslen = HCL_COUNTOF(buf);
@ -838,7 +842,7 @@ static hcl_errnum_t _syserrstrb (hcl_t* hcl, int syserr_type, int syserr_code, h
{ {
switch (syserr_type) switch (syserr_type)
{ {
case 2: case 2: /* specially for os2 */
#if defined(__OS2__) #if defined(__OS2__)
#if defined(TCPV40HDRS) #if defined(TCPV40HDRS)
if (buf) if (buf)
@ -887,10 +891,12 @@ static hcl_errnum_t _syserrstrb (hcl_t* hcl, int syserr_type, int syserr_code, h
#endif #endif
case 0: case 0:
#if defined(HAVE_STRERROR_R) #if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)
if (buf) strerror_s (buf, len, syserr_code);
#elif defined(HAVE_STRERROR_R)
if (buf) strerror_r (syserr_code, buf, len); if (buf) strerror_r (syserr_code, buf, len);
#else #else
/* this is not thread safe */ /* this may be thread unsafe */
if (buf) hcl_copy_bcstr (buf, len, strerror(syserr_code)); if (buf) hcl_copy_bcstr (buf, len, strerror(syserr_code));
#endif #endif
return errno_to_errnum(syserr_code); return errno_to_errnum(syserr_code);
@ -900,7 +906,6 @@ static hcl_errnum_t _syserrstrb (hcl_t* hcl, int syserr_type, int syserr_code, h
return HCL_ESYSERR; return HCL_ESYSERR;
} }
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
* ASSERTION SUPPORT * ASSERTION SUPPORT
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
@ -2755,8 +2760,8 @@ static void cb_opt_set (hcl_t* hcl, hcl_option_t id, const void* value)
id != HCL_LOG_TARGET_BCS && id != HCL_LOG_TARGET_UCS) return; /* return success. not interested */ id != HCL_LOG_TARGET_BCS && id != HCL_LOG_TARGET_UCS) return; /* return success. not interested */
#if defined(_WIN32) #if defined(_WIN32)
#if defined(HCL_OOCH_IS_UCH) #if defined(HCL_OOCH_IS_UCH) && (HCL_SIZEOF_UCH_T == HCL_SIZEOF_WCHAR_T)
fd = _open(hcl->option.log_target_u, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644); fd = _wopen(hcl->option.log_target_u, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644);
#else #else
fd = _open(hcl->option.log_target_b, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644); fd = _open(hcl->option.log_target_b, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY , 0644);
#endif #endif
@ -2765,7 +2770,7 @@ static void cb_opt_set (hcl_t* hcl, hcl_option_t id, const void* value)
#endif #endif
if (fd == -1) if (fd == -1)
{ {
/* TODO: any warning that log file not changed? */ /* TODO: any warning that log file not opened??? */
} }
else else
{ {
@ -2873,9 +2878,11 @@ static int open_pipes (hcl_t* hcl, int p[2])
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
/* Any equivalent in _WIN32?
flags = 1; flags = 1;
ioctl (p[0], FIONBIO, &flags); ioctl (p[0], FIONBIO, &flags);
ioctl (p[1], FIONBIO, &flags); ioctl (p[1], FIONBIO, &flags);
*/
#elif defined(__OS2__) #elif defined(__OS2__)
flags = 1; /* don't block */ flags = 1; /* don't block */
ioctl (p[0], FIONBIO, (char*)&flags, HCL_SIZEOF(flags)); ioctl (p[0], FIONBIO, (char*)&flags, HCL_SIZEOF(flags));
@ -3196,17 +3203,17 @@ static const hcl_bch_t* get_base_name (const hcl_bch_t* path)
return (last == HCL_NULL)? path: (last + 1); return (last == HCL_NULL)? path: (last + 1);
} }
static HCL_INLINE int open_cci_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
{
xtn_t* xtn = GET_XTN(hcl);
bb_t* bb = HCL_NULL;
#if defined(__DOS__) || defined(_WIN32) || defined(__OS2__) #if defined(__DOS__) || defined(_WIN32) || defined(__OS2__)
#define FOPEN_R_FLAGS "rb" #define FOPEN_R_FLAGS "rb"
#else #else
#define FOPEN_R_FLAGS "r" #define FOPEN_R_FLAGS "r"
#endif #endif
static HCL_INLINE int open_cci_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
{
xtn_t* xtn = GET_XTN(hcl);
bb_t* bb = HCL_NULL;
/* TOOD: support predefined include directory as well */ /* TOOD: support predefined include directory as well */
if (arg->includer) if (arg->includer)
{ {
@ -3726,7 +3733,6 @@ int hcl_attachudiostdwithucstr (hcl_t* hcl, const hcl_uch_t* udi_file, const hcl
HCL_ASSERT (hcl, xtn->udi_path == HCL_NULL); HCL_ASSERT (hcl, xtn->udi_path == HCL_NULL);
HCL_ASSERT (hcl, xtn->udo_path == HCL_NULL); HCL_ASSERT (hcl, xtn->udo_path == HCL_NULL);
xtn->udi_path = hcl_duputobcstr(hcl, udi_file, HCL_NULL); xtn->udi_path = hcl_duputobcstr(hcl, udi_file, HCL_NULL);
if (HCL_UNLIKELY(!xtn->udi_path)) if (HCL_UNLIKELY(!xtn->udi_path))
{ {