more fixes to use gem

This commit is contained in:
hyung-hwan 2019-12-18 05:15:03 +00:00
parent 4ee4e3fe60
commit 446925bcbf
17 changed files with 656 additions and 939 deletions

119
hawk/configure vendored
View File

@ -822,9 +822,9 @@ with_gnu_ld
with_sysroot
enable_libtool_lock
enable_largefile
enable_unicode
enable_experimental
enable_debug
enable_unicode
enable_full_liw
enable_intmax
enable_fltmax
@ -1480,11 +1480,11 @@ Optional Features:
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--disable-largefile omit support for large files
--enable-experimental enable experimental feature(default. no)
--enable-debug compile the code in the debug mode (default. no)
--enable-unicode Use the unicode character type as the default
character type. one of yes, no, yes:2, yes:4, no:2,
no:4 (default. yes)
--enable-experimental enable experimental feature(default. no)
--enable-debug compile the code in the debug mode (default. no)
--enable-full-liw Use a full word as a large integer word (default.
no)
--enable-intmax use hawk_intmax_t for integers (default. no)
@ -18266,6 +18266,63 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# Check whether --enable-unicode was given.
if test "${enable_unicode+set}" = set; then :
enableval=$enable_unicode; enable_unicode=$enableval
else
enable_unicode=yes
fi
if test "${enable_unicode}" = "yes:4"
then
$as_echo "#define HAWK_UNICODE_SIZE 4" >>confdefs.h
$as_echo "#define HAWK_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
elif test "${enable_unicode}" = "yes:2" -o "${enable_unicode}" = "yes"
then
$as_echo "#define HAWK_UNICODE_SIZE 2" >>confdefs.h
$as_echo "#define HAWK_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
CFLAGS="$CFLAGS -fshort-wchar"
CXXFLAGS="$CXXFLAGS -fshort-wchar"
fi
elif test "${enable_unicode}" = "no:4"
then
$as_echo "#define HAWK_UNICODE_SIZE 4" >>confdefs.h
else
$as_echo "#define HAWK_UNICODE_SIZE 2" >>confdefs.h
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
CFLAGS="$CFLAGS -fshort-wchar"
CXXFLAGS="$CXXFLAGS -fshort-wchar"
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_memset" >&5
$as_echo_n "checking for __builtin_memset... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@ -22345,62 +22402,6 @@ $as_echo "#define HAWK_BUILD_RELEASE 1" >>confdefs.h
fi
# Check whether --enable-unicode was given.
if test "${enable_unicode+set}" = set; then :
enableval=$enable_unicode; enable_unicode=$enableval
else
enable_unicode=yes
fi
if test "${enable_unicode}" = "yes:4"
then
$as_echo "#define HAWK_UNICODE_SIZE 4" >>confdefs.h
$as_echo "#define HAWK_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
elif test "${enable_unicode}" = "yes:2" -o "{enable_unicode}" = "yes"
then
$as_echo "#define HAWK_UNICODE_SIZE 2" >>confdefs.h
$as_echo "#define HAWK_ENABLE_UNICODE 1" >>confdefs.h
if test "${platform_win32}" = "yes"
then
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"
fi
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
CFLAGS="$CFLAGS -fshort-wchar"
CXXFLAGS="$CXXFLAGS -fshort-wchar"
fi
elif test "${enable_unicode}" = "no:4"
then
$as_echo "#define HAWK_UNICODE_SIZE 4" >>confdefs.h
else
$as_echo "#define HAWK_UNICODE_SIZE 2" >>confdefs.h
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
CFLAGS="$CFLAGS -fshort-wchar"
CXXFLAGS="$CXXFLAGS -fshort-wchar"
fi
fi
# Check whether --enable-full-liw was given.
if test "${enable_full_liw+set}" = set; then :
enableval=$enable_full_liw; enable_full_liw=$enableval

View File

@ -91,6 +91,52 @@ AC_SUBST(LIBM, $LIBM)
AX_PTHREAD()
dnl ===== enable-unicode =====
dnl this enable option is placed way above other options
dnl as -fshort-wchar affects the size of wchar_t.
AC_ARG_ENABLE([unicode],
[AS_HELP_STRING([--enable-unicode],[Use the unicode character type as the default character type. one of yes, no, yes:2, yes:4, no:2, no:4 (default. yes)])],
enable_unicode=$enableval,
enable_unicode=yes
)
if test "${enable_unicode}" = "yes:4"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[4],[Unicode character type size])
AC_DEFINE([HAWK_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
elif test "${enable_unicode}" = "yes:2" -o "${enable_unicode}" = "yes"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[2],[Unicode character type size])
AC_DEFINE([HAWK_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
[CFLAGS="$CFLAGS -fshort-wchar"]
[CXXFLAGS="$CXXFLAGS -fshort-wchar"]
fi
elif test "${enable_unicode}" = "no:4"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[4],[Unicode character type size])
else
dnl no:2, no, or anything else
AC_DEFINE([HAWK_UNICODE_SIZE],[2],[Unicode character type size])
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
[CFLAGS="$CFLAGS -fshort-wchar"]
[CXXFLAGS="$CXXFLAGS -fshort-wchar"]
fi
fi
dnl check some compiler builtins
AC_MSG_CHECKING([for __builtin_memset])
AC_LINK_IFELSE(
@ -722,49 +768,6 @@ else
AC_SUBST(BUILD_MODE, "release")
fi
dnl ===== enable-unicode =====
AC_ARG_ENABLE([unicode],
[AS_HELP_STRING([--enable-unicode],[Use the unicode character type as the default character type. one of yes, no, yes:2, yes:4, no:2, no:4 (default. yes)])],
enable_unicode=$enableval,
enable_unicode=yes
)
if test "${enable_unicode}" = "yes:4"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[4],[Unicode character type size])
AC_DEFINE([HAWK_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
elif test "${enable_unicode}" = "yes:2" -o "{enable_unicode}" = "yes"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[2],[Unicode character type size])
AC_DEFINE([HAWK_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
if test "${platform_win32}" = "yes"
then
[CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"]
[CXXFLAGS="$CXXFLAGS -DUNICODE -D_UNICODE"]
fi
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
[CFLAGS="$CFLAGS -fshort-wchar"]
[CXXFLAGS="$CXXFLAGS -fshort-wchar"]
fi
elif test "${enable_unicode}" = "no:4"
then
AC_DEFINE([HAWK_UNICODE_SIZE],[4],[Unicode character type size])
else
dnl no:2, no, or anything else
AC_DEFINE([HAWK_UNICODE_SIZE],[2],[Unicode character type size])
if test "${ac_cv_cflags__fshort_wchar}" = "yes"
then
[CFLAGS="$CFLAGS -fshort-wchar"]
[CXXFLAGS="$CXXFLAGS -fshort-wchar"]
fi
fi
dnl ===== enable-full-liw =====
AC_ARG_ENABLE([full-liw],
[AS_HELP_STRING([--enable-full-liw],[Use a full word as a large integer word (default. no)])],

View File

@ -53,6 +53,9 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("interrupted"),
HAWK_T("broken pipe"),
HAWK_T("in progress"),
HAWK_T("no handle"),
HAWK_T("no child process"),
HAWK_T("timed out"),
HAWK_T("cannot open '${0}'"),
HAWK_T("cannot read '${0}'"),

View File

@ -781,6 +781,9 @@ enum hawk_errnum_t
HAWK_EINTR, /**< interrupted */
HAWK_EPIPE, /**< broken pipe */
HAWK_EINPROG, /**< in progress */
HAWK_ENOHND, /**< no handle */
HAWK_ECHILD, /**< no child process */
HAWK_ETMOUT, /**< timed out */
/* mostly parse errors */
HAWK_EOPEN, /**< cannot open '${0}' */
@ -1255,6 +1258,9 @@ typedef enum hawk_log_mask_t hawk_log_mask_t;
*/
#if (HAWK_SIZEOF_UCH_T == HAWK_SIZEOF_BCH_T)
# define HAWK_UT(txt) (txt)
#elif defined(HAWK_UCH_IS_CHAR16_T) && (HAWK_SIZEOF_WCHAR_T == 2)
/* prefer L to u as u is not supported by some compiers despite char16_t support */
# define HAWK_UT(txt) (L ## txt)
#elif defined(HAWK_UCH_IS_CHAR16_T)
# define HAWK_UT(txt) (u ## txt)
#else

View File

@ -82,7 +82,7 @@ typedef struct hawk_mtx_t hawk_mtx_t;
struct hawk_mtx_t
{
hawk_t* hawk;
hawk_gem_t* gem;
hawk_mtx_hnd_t hnd;
};
@ -91,7 +91,7 @@ extern "C" {
#endif
HAWK_EXPORT hawk_mtx_t* hawk_mtx_open (
hawk_t* hawk,
hawk_gem_t* gem,
hawk_oow_t xtnsize
);
@ -101,7 +101,7 @@ HAWK_EXPORT void hawk_mtx_close (
HAWK_EXPORT int hawk_mtx_init (
hawk_mtx_t* mtx,
hawk_t* hawk
hawk_gem_t* gem
);
HAWK_EXPORT void hawk_mtx_fini (

View File

@ -136,37 +136,6 @@ struct hawk_pio_fnc_t
void* ctx;
};
/**
* The hawk_pio_errnum_t type defines error numbers.
*/
enum hawk_pio_errnum_t
{
HAWK_PIO_ENOERR = 0, /**< no error */
HAWK_PIO_EOTHER, /**< unknown error */
HAWK_PIO_ENOIMPL, /**< not implemented */
HAWK_PIO_ESYSERR, /**< subsystem error */
HAWK_PIO_EINTERN, /**< internal error */
HAWK_PIO_ENOMEM, /**< out of memory */
HAWK_PIO_EINVAL, /**< invalid parameter */
HAWK_PIO_EACCES, /**< access denied */
HAWK_PIO_EPERM, /**< operation not permitted */
HAWK_PIO_ENOENT, /**< no such file */
HAWK_PIO_EEXIST, /**< already exist */
HAWK_PIO_ENOTDIR, /**< not a directory */
HAWK_PIO_EINTR, /**< interrupted */
HAWK_PIO_EPIPE, /**< broken pipe */
HAWK_PIO_EINPROG, /**< in progress */
HAWK_PIO_EAGAIN, /**< resource not available temporarily */
HAWK_PIO_ENOHND, /**< no handle available */
HAWK_PIO_ECHILD, /**< the child is not valid */
HAWK_PIO_EILSEQ, /**< illegal sequence */
HAWK_PIO_EICSEQ, /**< incomplete sequence */
HAWK_PIO_EILCHR /**< illegal character */
};
typedef enum hawk_pio_errnum_t hawk_pio_errnum_t;
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* hawk_pio_hnd_t; /**< defines a pipe handle type */
@ -211,15 +180,12 @@ struct hawk_pio_pin_t
*/
struct hawk_pio_t
{
hawk_t* hawk;
hawk_gem_t* gem;
int flags; /**< options */
hawk_pio_errnum_t errnum; /**< error number */
hawk_pio_pid_t child; /**< handle to a child process */
hawk_pio_pin_t pin[3];
};
/** access the \a errnum field of the #hawk_pio_t structure */
#define HAWK_PIO_ERRNUM(pio) ((pio)->errnum)
/** access the \a child field of the #hawk_pio_t structure */
#define HAWK_PIO_CHILD(pio) ((pio)->child)
/** get the native handle from the #hawk_pio_t structure */
@ -242,7 +208,7 @@ extern "C" {
* \return #hawk_pio_t object on success, #HAWK_NULL on failure
*/
HAWK_EXPORT hawk_pio_t* hawk_pio_open (
hawk_t* hawk, /**< hawk */
hawk_gem_t* gem, /**< hawk */
hawk_oow_t ext, /**< extension size */
const hawk_ooch_t* cmd, /**< command to execute */
int flags /**< 0 or a number OR'ed of the
@ -265,7 +231,7 @@ HAWK_EXPORT void hawk_pio_close (
*/
HAWK_EXPORT int hawk_pio_init (
hawk_pio_t* pio, /**< pio object */
hawk_t* hawk, /**< hawk */
hawk_gem_t* gem, /**< hawk */
const hawk_ooch_t* cmd, /**< command to execute */
int flags /**< 0 or a number OR'ed of the
#hawk_pio_flag_t enumerators*/
@ -285,15 +251,6 @@ static HAWK_INLINE void* hawk_pio_getxtn (hawk_pio_t* pio) { return (void*)(pio
#define hawk_pio_getxtn(awk) ((void*)((hawk_pio_t*)(pio) + 1))
#endif
/**
* The hawk_pio_geterrnum() function returns the number of the last error
* occurred.
* \return error number
*/
HAWK_EXPORT hawk_pio_errnum_t hawk_pio_geterrnum (
const hawk_pio_t* pio /**< pio object */
);
/**
* The hawk_pio_getcmgr() function returns the current character manager.
* It returns #HAWK_NULL is \a pio is not opened with #HAWK_PIO_TEXT.
@ -355,15 +312,15 @@ HAWK_EXPORT hawk_ooi_t hawk_pio_read (
HAWK_EXPORT hawk_ooi_t hawk_pio_write (
hawk_pio_t* pio, /**< pio object */
hawk_pio_hid_t hid, /**< handle ID */
const void* data, /**< data to write */
hawk_oow_t size /**< data size */
const void* data, /**< data to write */
hawk_oow_t size /**< data size */
);
HAWK_EXPORT hawk_ooi_t hawk_pio_writebytes (
hawk_pio_t* pio, /**< pio object */
hawk_pio_hid_t hid, /**< handle ID */
const void* data, /**< data to write */
hawk_oow_t size /**< data size */
const void* data, /**< data to write */
hawk_oow_t size /**< data size */
);
/**

View File

@ -64,31 +64,6 @@ enum hawk_sio_flag_t
HAWK_SIO_SEQUENTIAL = HAWK_FIO_SEQUENTIAL
};
enum hawk_sio_errnum_t
{
HAWK_SIO_ENOERR = 0, /**< no error */
HAWK_SIO_EOTHER, /**< other error */
HAWK_SIO_ENOIMPL, /**< not implemented */
HAWK_SIO_ESYSERR, /**< subsystem(system call) error */
HAWK_SIO_EINTERN, /**< internal error */
HAWK_SIO_ENOMEM, /**< out of memory */
HAWK_SIO_EINVAL, /**< invalid parameter */
HAWK_SIO_EACCES, /**< access denied */
HAWK_SIO_EPERM, /**< operation not permitted */
HAWK_SIO_ENOENT, /**< no such file */
HAWK_SIO_EEXIST, /**< already exist */
HAWK_SIO_ENOTDIR, /**< not a directory */
HAWK_SIO_EINTR, /**< interrupted */
HAWK_SIO_EPIPE, /**< broken pipe */
HAWK_SIO_EAGAIN, /**< resource not available temporarily */
HAWK_SIO_EILSEQ, /**< illegal sequence */
HAWK_SIO_EICSEQ, /**< incomplete sequence */
HAWK_SIO_EILCHR /**< illegal character */
};
typedef enum hawk_sio_errnum_t hawk_sio_errnum_t;
typedef hawk_fio_off_t hawk_sio_pos_t;
typedef hawk_fio_hnd_t hawk_sio_hnd_t;
typedef hawk_fio_std_t hawk_sio_std_t;
@ -110,8 +85,7 @@ typedef struct hawk_sio_t hawk_sio_t;
struct hawk_sio_t
{
hawk_t* hawk;
hawk_sio_errnum_t errnum;
hawk_gem_t* gem;
hawk_fio_t file;
@ -143,14 +117,14 @@ extern "C" {
* The hawk_sio_open() fucntion creates a stream object.
*/
HAWK_EXPORT hawk_sio_t* hawk_sio_open (
hawk_t* hawk, /**< memory manager */
hawk_gem_t* gem,
hawk_oow_t xtnsize, /**< extension size in bytes */
const hawk_ooch_t* file, /**< file name */
int flags /**< number OR'ed of #hawk_sio_flag_t */
);
HAWK_EXPORT hawk_sio_t* hawk_sio_openstd (
hawk_t* hawk, /**< memory manager */
hawk_gem_t* gem,
hawk_oow_t xtnsize, /**< extension size in bytes */
hawk_sio_std_t std, /**< standard I/O identifier */
int flags /**< number OR'ed of #hawk_sio_flag_t */
@ -165,14 +139,14 @@ HAWK_EXPORT void hawk_sio_close (
HAWK_EXPORT int hawk_sio_init (
hawk_sio_t* sio,
hawk_t* hawk,
hawk_gem_t* gem,
const hawk_ooch_t* file,
int flags
);
HAWK_EXPORT int hawk_sio_initstd (
hawk_sio_t* sio,
hawk_t* hawk,
hawk_gem_t* gem,
hawk_sio_std_t std,
int flags
);
@ -187,10 +161,6 @@ static HAWK_INLINE void* hawk_sio_getxtn (hawk_sio_t* sio) { return (void*)(sio
#define hawk_sio_getxtn(awk) ((void*)((hawk_sio_t*)(sio) + 1))
#endif
HAWK_EXPORT hawk_sio_errnum_t hawk_sio_geterrnum (
const hawk_sio_t* sio
);
HAWK_EXPORT hawk_cmgr_t* hawk_sio_getcmgr (
hawk_sio_t* sio
);

View File

@ -29,29 +29,6 @@
#include <hawk-cmn.h>
enum hawk_tio_errnum_t
{
HAWK_TIO_ENOERR = 0, /**< no error */
HAWK_TIO_EOTHER, /**< other error */
HAWK_TIO_ENOIMPL, /**< not implmeneted */
HAWK_TIO_ESYSERR, /**< subsystem error */
HAWK_TIO_EINTERN, /**< internal error */
HAWK_TIO_ENOMEM, /**< out of memory */
HAWK_TIO_EINVAL, /**< invalid parameter */
HAWK_TIO_EACCES, /**< access denied */
HAWK_TIO_EPERM, /**< operation not permitted */
HAWK_TIO_ENOENT, /**< no such file */
HAWK_TIO_ENOSPC, /**< no more space */
HAWK_TIO_EILSEQ, /**< illegal sequence */
HAWK_TIO_EICSEQ, /**< incomplete sequence */
HAWK_TIO_EILCHR, /**< illegal character */
HAWK_TIO_ENINPF, /**< no input function attached */
HAWK_TIO_ENOUTF /**< no output function attached */
};
typedef enum hawk_tio_errnum_t hawk_tio_errnum_t;
enum hawk_tio_cmd_t
{
HAWK_TIO_OPEN,
@ -76,8 +53,6 @@ enum hawk_tio_misc_t
HAWK_TIO_MINOUTBUFCAPA = 32
};
#define HAWK_TIO_ERRNUM(tio) ((const hawk_tio_errnum_t)(tio)->errnum)
typedef struct hawk_tio_t hawk_tio_t;
/**
@ -109,8 +84,7 @@ typedef struct hawk_tio_io_t hawk_tio_io_t;
*/
struct hawk_tio_t
{
hawk_t* hawk;
hawk_tio_errnum_t errnum;
hawk_gem_t* gem;
int flags;
hawk_cmgr_t* cmgr;
@ -132,7 +106,7 @@ extern "C" {
* The hawk_tio_open() function creates an text stream processoor.
*/
HAWK_EXPORT hawk_tio_t* hawk_tio_open (
hawk_t* hawk, /**< hawk */
hawk_gem_t* gem,
hawk_oow_t xtnsize, /**< extension size in bytes */
int flags /**< ORed of hawk_tio_flag_t enumerators */
);
@ -150,7 +124,7 @@ HAWK_EXPORT int hawk_tio_close (
*/
HAWK_EXPORT int hawk_tio_init (
hawk_tio_t* tio,
hawk_t* hawk,
hawk_gem_t* gem,
int flags
);
@ -167,22 +141,6 @@ static HAWK_INLINE void* hawk_tio_getxtn (hawk_tio_t* tio) { return (void*)(tio
#define hawk_tio_getxtn(awk) ((void*)((hawk_tio_t*)(tio) + 1))
#endif
/**
* The hawk_tio_geterrnum() function returns the current error code.
*/
HAWK_EXPORT hawk_tio_errnum_t hawk_tio_geterrnum (
const hawk_tio_t* tio
);
/**
* The hawk_tio_geterrnum() function changes the current error code.
* typically from within the I/O handler attached.
*/
HAWK_EXPORT void hawk_tio_seterrnum (
hawk_tio_t* tio,
hawk_tio_errnum_t errnum
);
/**
* The hawk_tio_getcmgr() function returns the character manager.
*/
@ -222,10 +180,10 @@ HAWK_EXPORT int hawk_tio_detachin (
* @return 0 on success, -1 on failure
*/
HAWK_EXPORT int hawk_tio_attachout (
hawk_tio_t* tio,
hawk_tio_t* tio,
hawk_tio_io_impl_t output,
hawk_bch_t* bufptr,
hawk_oow_t bufcapa
hawk_bch_t* bufptr,
hawk_oow_t bufcapa
);
/**

View File

@ -30,6 +30,16 @@
#include "hawk-cmn.h"
#include <stdarg.h>
#define HAWK_EPOCH_YEAR (1970)
#define HAWK_EPOCH_MON (1)
#define HAWK_EPOCH_DAY (1)
#define HAWK_EPOCH_WDAY (4)
/* windows specific epoch time */
#define HAWK_EPOCH_YEAR_WIN (1601)
#define HAWK_EPOCH_MON_WIN (1)
#define HAWK_EPOCH_DAY_WIN (1)
/* =========================================================================
* DOUBLY LINKED LIST
* ========================================================================= */

View File

@ -2372,7 +2372,7 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
if (!mctx->log.dmsgbuf) mctx->log.dmsgbuf = hawk_becs_open(hawk_rtx_getmmgr(rtx), 0, 0);
if (!mctx->log.dmsgbuf) goto done;
if (hawk_gettime(&now) || hawk_localtime(&now, &cnow) <= -1) goto done;
if (hawk_get_time(&now) || hawk_localtime(&now, &cnow) <= -1) goto done;
if (hawk_becs_fmt (
mctx->log.dmsgbuf, HAWK_BT("<%d>%s %02d %02d:%02d:%02d "),

View File

@ -41,10 +41,8 @@
#elif defined(__DOS__)
/* implement this */
#elif defined(__BEOS__)
# include <be/kernel/OS.h>
#else
# include "syscall.h"
# if defined(AIX) && defined(__GNUC__)
typedef int crid_t;
typedef unsigned int class_id_t;
@ -52,16 +50,19 @@
# include <pthread.h>
#endif
hawk_mtx_t* hawk_mtx_open (hawk_t* hawk, hawk_oow_t xtnsize)
#include "syserr.h"
IMPLEMENT_SYSERR_TO_ERRNUM (hawk, HAWK)
hawk_mtx_t* hawk_mtx_open (hawk_gem_t* gem, hawk_oow_t xtnsize)
{
hawk_mtx_t* mtx;
mtx = (hawk_mtx_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_mtx_t) + xtnsize);
mtx = (hawk_mtx_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_mtx_t) + xtnsize);
if (mtx)
{
if (hawk_mtx_init(mtx, hawk) <= -1)
if (hawk_mtx_init(mtx, gem) <= -1)
{
hawk_freemem (hawk, mtx);
hawk_gem_freemem (gem, mtx);
return HAWK_NULL;
}
else HAWK_MEMSET (mtx + 1, 0, xtnsize);
@ -73,17 +74,21 @@ hawk_mtx_t* hawk_mtx_open (hawk_t* hawk, hawk_oow_t xtnsize)
void hawk_mtx_close (hawk_mtx_t* mtx)
{
hawk_mtx_fini (mtx);
hawk_freemem (mtx->hawk, mtx);
hawk_gem_freemem (mtx->gem, mtx);
}
int hawk_mtx_init (hawk_mtx_t* mtx, hawk_t* hawk)
int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem)
{
HAWK_MEMSET (mtx, 0, HAWK_SIZEOF(*mtx));
mtx->hawk = hawk;
mtx->gem = gem;
#if defined(_WIN32)
mtx->hnd = CreateMutex(HAWK_NULL, FALSE, HAWK_NULL);
if (mtx->hnd == HAWK_NULL) return -1;
if (mtx->hnd == HAWK_NULL)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
#elif defined(__OS2__)
@ -92,7 +97,11 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_t* hawk)
HMTX m;
rc = DosCreateMutexSem(HAWK_NULL, &m, DC_SEM_SHARED, FALSE);
if (rc != NO_ERROR) return -1;
if (rc != NO_ERROR)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(rc));
return -1;
}
mtx->hnd = m;
}
@ -100,10 +109,6 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_t* hawk)
#elif defined(__DOS__)
# error not implemented
#elif defined(__BEOS__)
mtx->hnd = create_sem(1, HAWK_NULL);
if (mtx->hnd < B_OK) return -1;
#else
/*
hawk_ensure (pthread_mutexattr_init (&attr) == 0);
@ -118,7 +123,15 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_t* hawk)
hawk_ensure (pthread_mutex_init (&mtx->hnd, &attr) == 0);
hawk_ensure (pthread_mutexattr_destroy (&attr) == 0);
*/
if (pthread_mutex_init((pthread_mutex_t*)&mtx->hnd, HAWK_NULL) != 0) return -1;
{
int n;
n = pthread_mutex_init((pthread_mutex_t*)&mtx->hnd, HAWK_NULL);
if (n != 0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(n));
return -1;
}
}
#endif
return 0;
@ -135,10 +148,6 @@ void hawk_mtx_fini (hawk_mtx_t* mtx)
#elif defined(__DOS__)
# error not implemented
#elif defined(__BEOS__)
/*if (delete_sem(mtx->hnd) != B_NO_ERROR) return -1;*/
delete_sem(mtx->hnd);
#else
pthread_mutex_destroy ((pthread_mutex_t*)&mtx->hnd);
#endif
@ -161,45 +170,62 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
*/
if (waiting_time)
{
DWORD msec;
DWORD msec, ret;
msec = HAWK_SECNSEC_TO_MSEC(waiting_time->sec, waiting_time->nsec);
if (WaitForSingleObject(mtx->hnd, msec) != WAIT_OBJECT_0) return -1;
ret = WaitForSingleObject(mtx->hnd, msec);
if (ret == WAIT_TIMEOUT)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, HAWK_ETMOUT);
return -1;
}
else if (ret == WAIT_ABANDONED)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, HAWK_ESYSERR);
return -1;
}
else if (ret != WAIT_OBJECT_0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
}
else
{
if (WaitForSingleObject(mtx->hnd, INFINITE) == WAIT_FAILED) return -1;
if (WaitForSingleObject(mtx->hnd, INFINITE) == WAIT_FAILED)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
}
#elif defined(__OS2__)
if (waiting_time)
{
ULONG msec;
APIRET rc;
msec = HAWK_SECNSEC_TO_MSEC(waiting_time->sec, waiting_time->nsec);
if (DosRequestMutexSem(mtx->hnd, msec) != NO_ERROR) return -1;
rc = DosRequestMutexSem(mtx->hnd, msec);
if (rc != NO_ERROR)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(rc));
return -1;
}
}
else
{
if (DosRequestMutexSem(mtx->hnd, SEM_INDEFINITE_WAIT) != NO_ERROR) return -1;
APIRET rc;
rc = DosRequestMutexSem(mtx->hnd, SEM_INDEFINITE_WAIT);
if (rc != NO_ERROR)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(rc));
return -1;
}
}
#elif defined(__DOS__)
/* nothing to do */
#elif defined(__BEOS__)
if (waiting_time)
{
/* TODO: check for B_WOULD_BLOCK */
/*if (acquire_sem_etc(mtx->hnd, 1, B_ABSOLUTE_TIMEOUT, 0) != B_NO_ERROR) return -1;*/
bigtime_t usec;
usec = HAWK_SECNSEC_TO_USEC(waiting_time->sec, waiting_time->nsec);
if (acquire_sem_etc(mtx->hnd, 1, B_TIMEOUT, usec) != B_NO_ERROR) return -1;
}
else
{
if (acquire_sem(mtx->hnd) != B_NO_ERROR) return -1;
}
#else
/* if pthread_mutex_timedlock() isn't available, don't honor the waiting time. */
@ -208,19 +234,30 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
{
hawk_ntime_t t;
struct timespec ts;
int n;
hawk_get_time (&t);
hawk_add_time (&t, waiting_time, &t);
ts.tv_sec = t.sec;
ts.tv_nsec = t.nsec;
if (pthread_mutex_timedlock((pthread_mutex_t*)&mtx->hnd, &ts) != 0) return -1;
n = pthread_mutex_timedlock((pthread_mutex_t*)&mtx->hnd, &ts);
if (n != 0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(n));
return -1;
}
}
else
{
#endif
if (pthread_mutex_lock((pthread_mutex_t*)&mtx->hnd) != 0) return -1;
int n;
n = pthread_mutex_lock((pthread_mutex_t*)&mtx->hnd);
if (n != 0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(n));
return -1;
}
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
}
#endif
@ -232,20 +269,33 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
int hawk_mtx_unlock (hawk_mtx_t* mtx)
{
#if defined(_WIN32)
if (ReleaseMutex (mtx->hnd) == FALSE) return -1;
if (ReleaseMutex(mtx->hnd) == FALSE)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
#elif defined(__OS2__)
if (DosReleaseMutexSem (mtx->hnd) != NO_ERROR) return -1;
APIRET rc;
rc = DosReleaseMutexSem(mtx->hnd);
if (rc != NO_ERROR)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(rc));
return -1;
}
#elif defined(__DOS__)
/* nothing to do */
#elif defined(__BEOS__)
if (release_sem(mtx->hnd) != B_NO_ERROR) return -1;
#else
if (pthread_mutex_unlock ((pthread_mutex_t*)&mtx->hnd) != 0) return -1;
int n;
n = pthread_mutex_unlock((pthread_mutex_t*)&mtx->hnd);
if (n != 0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(n));
return -1;
}
#endif
return 0;
}
@ -253,28 +303,47 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx)
int hawk_mtx_trylock (hawk_mtx_t* mtx)
{
#if defined(_WIN32)
if (WaitForSingleObject(mtx->hnd, 0) != WAIT_OBJECT_0) return -1;
if (WaitForSingleObject(mtx->hnd, 0) != WAIT_OBJECT_0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
#elif defined(__OS2__)
if (DosRequestMutexSem(mtx->hnd, 0) != NO_ERROR) return -1;
APIRET rc;
rc = DosRequestMutexSem(mtx->hnd, 0);
if (rc != NO_ERROR)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(rc));
return -1;
}
#elif defined(__DOS__)
/* nothing to do */
#elif defined(__BEOS__)
if (acquire_sem_etc(mtx->hnd, 1, B_TIMEOUT, 0) != B_NO_ERROR) return -1;
#else
#if defined(HAVE_PTHREAD_MUTEX_TRYLOCK)
if (pthread_mutex_trylock((pthread_mutex_t*)&mtx->hnd) != 0) return -1;
#elif defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
hawk_ntime_t t;
struct timespec ts;
hawk_gettime (&t);
ts.tv_sec = t.sec;
ts.tv_nsec = t.nsec;
if (pthread_mutex_timedlock((pthread_mutex_t*)&mtx->hnd, &ts) != 0) return -1;
#else
/* -------------------------------------------------- */
int n;
#if defined(HAVE_PTHREAD_MUTEX_TRYLOCK)
n = pthread_mutex_trylock((pthread_mutex_t*)&mtx->hnd);
#elif defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
hawk_ntime_t t;
struct timespec ts;
hawk_get_time (&t);
ts.tv_sec = t.sec;
ts.tv_nsec = t.nsec;
n = pthread_mutex_timedlock((pthread_mutex_t*)&mtx->hnd, &ts);
#else
/* not supported. fallback to normal pthread_mutex_lock(). <--- is this really desirable? */
if (pthread_mutex_lock((pthread_mutex_t*)&mtx->hnd) != 0) return -1;
/* not supported. fallback to normal pthread_mutex_lock(). <--- is this really desirable? */
n = pthread_mutex_lock((pthread_mutex_t*)&mtx->hnd);
#endif
if (n != 0)
{
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, syserr_to_errnum(n));
return -1;
}
/* -------------------------------------------------- */
#endif
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,8 @@
# include "syscall.h"
#endif
#include "syserr.h"
IMPLEMENT_SYSERR_TO_ERRNUM (hawk, HAWK)
#define LOCK_OUTPUT(sio) do { if ((sio)->mtx) hawk_mtx_lock ((sio)->mtx, HAWK_NULL); } while(0)
#define UNLOCK_OUTPUT(sio) do { if ((sio)->mtx) hawk_mtx_unlock ((sio)->mtx); } while(0)
@ -56,68 +58,16 @@ enum
static hawk_ooi_t file_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
static hawk_ooi_t file_output (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, hawk_oow_t size);
static hawk_sio_errnum_t fio_errnum_to_sio_errnum (hawk_fio_t* fio)
{
switch (fio->errnum)
{
case HAWK_FIO_ENOMEM:
return HAWK_SIO_ENOMEM;
case HAWK_FIO_EINVAL:
return HAWK_SIO_EINVAL;
case HAWK_FIO_EACCES:
return HAWK_SIO_EACCES;
case HAWK_FIO_ENOENT:
return HAWK_SIO_ENOENT;
case HAWK_FIO_EEXIST:
return HAWK_SIO_EEXIST;
case HAWK_FIO_EINTR:
return HAWK_SIO_EINTR;
case HAWK_FIO_EPIPE:
return HAWK_SIO_EPIPE;
case HAWK_FIO_EAGAIN:
return HAWK_SIO_EAGAIN;
case HAWK_FIO_ESYSERR:
return HAWK_SIO_ESYSERR;
case HAWK_FIO_ENOIMPL:
return HAWK_SIO_ENOIMPL;
default:
return HAWK_SIO_EOTHER;
}
}
static hawk_sio_errnum_t tio_errnum_to_sio_errnum (hawk_tio_t* tio)
{
switch (tio->errnum)
{
case HAWK_TIO_ENOMEM:
return HAWK_SIO_ENOMEM;
case HAWK_TIO_EINVAL:
return HAWK_SIO_EINVAL;
case HAWK_TIO_EACCES:
return HAWK_SIO_EACCES;
case HAWK_TIO_ENOENT:
return HAWK_SIO_ENOENT;
case HAWK_TIO_EILSEQ:
return HAWK_SIO_EILSEQ;
case HAWK_TIO_EICSEQ:
return HAWK_SIO_EICSEQ;
case HAWK_TIO_EILCHR:
return HAWK_SIO_EILCHR;
default:
return HAWK_SIO_EOTHER;
}
}
hawk_sio_t* hawk_sio_open (hawk_t* hawk, hawk_oow_t xtnsize, const hawk_ooch_t* file, int flags)
hawk_sio_t* hawk_sio_open (hawk_gem_t* gem, hawk_oow_t xtnsize, const hawk_ooch_t* file, int flags)
{
hawk_sio_t* sio;
sio = (hawk_sio_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_sio_t) + xtnsize);
sio = (hawk_sio_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_sio_t) + xtnsize);
if (sio)
{
if (hawk_sio_init(sio, hawk, file, flags) <= -1)
if (hawk_sio_init(sio, gem, file, flags) <= -1)
{
hawk_freemem (hawk, sio);
hawk_gem_freemem (gem, sio);
return HAWK_NULL;
}
else HAWK_MEMSET (sio + 1, 0, xtnsize);
@ -125,7 +75,7 @@ hawk_sio_t* hawk_sio_open (hawk_t* hawk, hawk_oow_t xtnsize, const hawk_ooch_t*
return sio;
}
hawk_sio_t* hawk_sio_openstd (hawk_t* hawk, hawk_oow_t xtnsize, hawk_sio_std_t std, int flags)
hawk_sio_t* hawk_sio_openstd (hawk_gem_t* gem, hawk_oow_t xtnsize, hawk_sio_std_t std, int flags)
{
hawk_sio_t* sio;
hawk_fio_hnd_t hnd;
@ -133,21 +83,20 @@ hawk_sio_t* hawk_sio_openstd (hawk_t* hawk, hawk_oow_t xtnsize, hawk_sio_std_t s
/* Is this necessary?
if (flags & HAWK_SIO_KEEPATH)
{
sio->errnum = HAWK_SIO_EINVAL;
hawk_gem_seterrnum (gem, HAWK_NULL, HAWK_EINVAL);
return HAWK_NULL;
}
*/
if (hawk_get_std_fio_handle(std, &hnd) <= -1) return HAWK_NULL;
sio = hawk_sio_open(hawk, xtnsize, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE);
sio = hawk_sio_open(gem, xtnsize, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE);
#if defined(_WIN32)
if (sio)
{
DWORD mode;
if (GetConsoleMode (sio->file.handle, &mode) == TRUE &&
GetConsoleOutputCP() == CP_UTF8)
if (GetConsoleMode(sio->file.handle, &mode) == TRUE && GetConsoleOutputCP() == CP_UTF8)
{
sio->status |= STATUS_UTF8_CONSOLE;
}
@ -160,62 +109,48 @@ hawk_sio_t* hawk_sio_openstd (hawk_t* hawk, hawk_oow_t xtnsize, hawk_sio_std_t s
void hawk_sio_close (hawk_sio_t* sio)
{
hawk_sio_fini (sio);
hawk_freemem (sio->hawk, sio);
hawk_gem_freemem (sio->gem, sio);
}
int hawk_sio_init (hawk_sio_t* sio, hawk_t* hawk, const hawk_ooch_t* path, int flags)
int hawk_sio_init (hawk_sio_t* sio, hawk_gem_t* gem, const hawk_ooch_t* path, int flags)
{
int mode;
int topt = 0;
HAWK_MEMSET (sio, 0, HAWK_SIZEOF(*sio));
sio->hawk = hawk;
sio->gem = gem;
mode = HAWK_FIO_RUSR | HAWK_FIO_WUSR | HAWK_FIO_RGRP | HAWK_FIO_ROTH;
if (flags & HAWK_SIO_REENTRANT)
{
sio->mtx = hawk_mtx_open(hawk, 0);
sio->mtx = hawk_mtx_open(gem, 0);
if (!sio->mtx) goto oops00;
}
/* sio flag enumerators redefines most fio flag enumerators and
* compose a superset of fio flag enumerators. when a user calls
* this function, a user can specify a sio flag enumerator not
* present in the fio flag enumerator. mask off such an enumerator. */
if (hawk_fio_init(&sio->file, hawk, path, (flags & ~HAWK_FIO_RESERVED), mode) <= -1)
{
sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
goto oops01;
}
if (hawk_fio_init(&sio->file, gem, path, (flags & ~HAWK_FIO_RESERVED), mode) <= -1) goto oops01;
if (flags & HAWK_SIO_IGNOREECERR) topt |= HAWK_TIO_IGNOREECERR;
if (flags & HAWK_SIO_NOAUTOFLUSH) topt |= HAWK_TIO_NOAUTOFLUSH;
if ((flags & HAWK_SIO_KEEPPATH) && !(flags & HAWK_SIO_HANDLE))
{
sio->path = hawk_dupoocstr(hawk, path, HAWK_NULL);
if (sio->path == HAWK_NULL)
{
sio->errnum = HAWK_SIO_ENOMEM;
goto oops02;
}
sio->path = hawk_gem_dupoocstr(gem, path, HAWK_NULL);
if (sio->path == HAWK_NULL) goto oops02;
}
if (hawk_tio_init(&sio->tio.io, hawk, topt) <= -1)
{
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
goto oops03;
}
if (hawk_tio_init(&sio->tio.io, gem, topt) <= -1) goto oops03;
/* store the back-reference to sio in the extension area.*/
HAWK_ASSERT (hawk, (&sio->tio.io + 1) == &sio->tio.xtn);
/*HAWK_ASSERT (hawk, (&sio->tio.io + 1) == &sio->tio.xtn);*/
*(hawk_sio_t**)(&sio->tio.io + 1) = sio;
if (hawk_tio_attachin(&sio->tio.io, file_input, sio->inbuf, HAWK_COUNTOF(sio->inbuf)) <= -1 ||
hawk_tio_attachout(&sio->tio.io, file_output, sio->outbuf, HAWK_COUNTOF(sio->outbuf)) <= -1)
{
if (sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
goto oops04;
}
@ -227,7 +162,7 @@ int hawk_sio_init (hawk_sio_t* sio, hawk_t* hawk, const hawk_ooch_t* path, int f
oops04:
hawk_tio_fini (&sio->tio.io);
oops03:
if (sio->path) hawk_freemem (sio->hawk, sio->path);
if (sio->path) hawk_gem_freemem (sio->gem, sio->path);
oops02:
hawk_fio_fini (&sio->file);
oops01:
@ -236,21 +171,20 @@ oops00:
return -1;
}
int hawk_sio_initstd (hawk_sio_t* sio, hawk_t* hawk, hawk_sio_std_t std, int flags)
int hawk_sio_initstd (hawk_sio_t* sio, hawk_gem_t* gem, hawk_sio_std_t std, int flags)
{
int n;
hawk_fio_hnd_t hnd;
if (hawk_get_std_fio_handle (std, &hnd) <= -1) return -1;
n = hawk_sio_init(sio, hawk, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE);
n = hawk_sio_init(sio, gem, (const hawk_ooch_t*)&hnd, flags | HAWK_SIO_HANDLE | HAWK_SIO_NOCLOSE);
#if defined(_WIN32)
if (n >= 0)
{
DWORD mode;
if (GetConsoleMode (sio->file.handle, &mode) == TRUE &&
GetConsoleOutputCP() == CP_UTF8)
if (GetConsoleMode (sio->file.handle, &mode) == TRUE && GetConsoleOutputCP() == CP_UTF8)
{
sio->status |= STATUS_UTF8_CONSOLE;
}
@ -266,17 +200,13 @@ void hawk_sio_fini (hawk_sio_t* sio)
hawk_sio_flush (sio);
hawk_tio_fini (&sio->tio.io);
hawk_fio_fini (&sio->file);
if (sio->path) hawk_freemem (sio->hawk, sio->path);
if (sio->path) hawk_gem_freemem (sio->gem, sio->path);
if (sio->mtx) hawk_mtx_close (sio->mtx);
}
hawk_sio_errnum_t hawk_sio_geterrnum (const hawk_sio_t* sio)
{
return sio->errnum;
}
hawk_cmgr_t* hawk_sio_getcmgr (hawk_sio_t* sio)
{
return hawk_tio_getcmgr (&sio->tio.io);
return hawk_tio_getcmgr(&sio->tio.io);
}
void hawk_sio_setcmgr (hawk_sio_t* sio, hawk_cmgr_t* cmgr)
@ -286,7 +216,7 @@ void hawk_sio_setcmgr (hawk_sio_t* sio, hawk_cmgr_t* cmgr)
hawk_sio_hnd_t hawk_sio_gethnd (const hawk_sio_t* sio)
{
/*return hawk_fio_gethnd (&sio->file);*/
/*return hawk_fio_gethnd(&sio->file);*/
return HAWK_FIO_HANDLE(&sio->file);
}
@ -299,12 +229,8 @@ const hawk_ooch_t* hawk_sio_getpath (hawk_sio_t* sio)
hawk_ooi_t hawk_sio_flush (hawk_sio_t* sio)
{
hawk_ooi_t n;
LOCK_OUTPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_flush(&sio->tio.io);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_OUTPUT (sio);
return n;
}
@ -319,28 +245,18 @@ void hawk_sio_drain (hawk_sio_t* sio)
hawk_ooi_t hawk_sio_getbchar (hawk_sio_t* sio, hawk_bch_t* c)
{
hawk_ooi_t n;
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readbchars(&sio->tio.io, c, 1);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_INPUT (sio);
return n;
}
hawk_ooi_t hawk_sio_getuchar (hawk_sio_t* sio, hawk_uch_t* c)
{
hawk_ooi_t n;
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readuchars(&sio->tio.io, c, 1);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_INPUT (sio);
return n;
}
@ -356,17 +272,11 @@ hawk_ooi_t hawk_sio_getbcstr (hawk_sio_t* sio, hawk_bch_t* buf, hawk_oow_t size)
#endif
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readbchars(&sio->tio.io, buf, size - 1);
if (n <= -1)
{
if (sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
return -1;
}
if (n <= -1) return -1;
UNLOCK_INPUT (sio);
buf[n] = HAWK_BT('\0');
buf[n] = '\0';
return n;
}
@ -379,10 +289,7 @@ hawk_ooi_t hawk_sio_getbchars (hawk_sio_t* sio, hawk_bch_t* buf, hawk_oow_t size
#endif
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readbchars(&sio->tio.io, buf, size);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_INPUT (sio);
return n;
@ -400,17 +307,10 @@ hawk_ooi_t hawk_sio_getucstr (hawk_sio_t* sio, hawk_uch_t* buf, hawk_oow_t size)
#endif
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readuchars(&sio->tio.io, buf, size - 1);
if (n <= -1)
{
if (sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
return -1;
}
UNLOCK_INPUT (sio);
buf[n] = HAWK_UT('\0');
buf[n] = '\0';
return n;
}
@ -424,10 +324,7 @@ hawk_ooi_t hawk_sio_getuchars(hawk_sio_t* sio, hawk_uch_t* buf, hawk_oow_t size)
#endif
LOCK_INPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_readuchars (&sio->tio.io, buf, size);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_INPUT (sio);
return n;
@ -437,20 +334,15 @@ static hawk_ooi_t putbc_no_mutex (hawk_sio_t* sio, hawk_bch_t c)
{
hawk_ooi_t n;
sio->errnum = HAWK_SIO_ENOERR;
#if defined(__OS2__)
if (c == HAWK_BT('\n') && (sio->status & STATUS_LINE_BREAK))
n = hawk_tio_writebchars (&sio->tio.io, HAWK_BT("\r\n"), 2);
if (c == '\n' && (sio->status & STATUS_LINE_BREAK))
n = hawk_tio_writebchars(&sio->tio.io, "\r\n", 2);
else
n = hawk_tio_writebchars (&sio->tio.io, &c, 1);
n = hawk_tio_writebchars(&sio->tio.io, &c, 1);
#else
n = hawk_tio_writebchars (&sio->tio.io, &c, 1);
n = hawk_tio_writebchars(&sio->tio.io, &c, 1);
#endif
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
return n;
}
@ -467,17 +359,17 @@ static hawk_ooi_t put_uchar_no_mutex (hawk_sio_t* sio, hawk_uch_t c)
{
hawk_ooi_t n;
sio->errnum = HAWK_SIO_ENOERR;
#if defined(__OS2__)
if (c == HAWK_UT('\n') && (sio->status & STATUS_LINE_BREAK))
n = hawk_tio_writeuchars(&sio->tio.io, HAWK_UT("\r\n"), 2);
if (c == '\n' && (sio->status & STATUS_LINE_BREAK))
{
static hawk_uch_t crnl[2] = { '\r', '\n' };
n = hawk_tio_writeuchars(&sio->tio.io, crnl, 2);
}
else
n = hawk_tio_writeuchars(&sio->tio.io, &c, 1);
#else
n = hawk_tio_writeuchars(&sio->tio.io, &c, 1);
#endif
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
return n;
}
@ -502,9 +394,13 @@ hawk_ooi_t hawk_sio_putbcstr (hawk_sio_t* sio, const hawk_bch_t* str)
if (sio->status & STATUS_LINE_BREAK)
{
LOCK_OUTPUT (sio);
for (n = 0; n < HAWK_TYPE_MAX(hawk_ooi_t) && str[n] != HAWK_BT('\0'); n++)
for (n = 0; n < HAWK_TYPE_MAX(hawk_ooi_t) && str[n] != '\0'; n++)
{
if ((n = putbc_no_mutex(sio, str[n])) <= -1) return n;
if ((n = putbc_no_mutex(sio, str[n])) <= -1)
{
n = -1;
break;
}
}
UNLOCK_OUTPUT (sio);
return n;
@ -512,12 +408,7 @@ hawk_ooi_t hawk_sio_putbcstr (hawk_sio_t* sio, const hawk_bch_t* str)
#endif
LOCK_OUTPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_writebchars(&sio->tio.io, str, (hawk_oow_t)-1);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum(&sio->tio.io);
UNLOCK_OUTPUT (sio);
return n;
}
@ -536,7 +427,11 @@ hawk_ooi_t hawk_sio_putbchars (hawk_sio_t* sio, const hawk_bch_t* str, hawk_oow_
LOCK_OUTPUT (sio);
for (n = 0; n < size; n++)
{
if (putbc_no_mutex(sio, str[n]) <= -1) return -1;
if (putbc_no_mutex(sio, str[n]) <= -1)
{
n = -1;
break;
}
}
UNLOCK_OUTPUT (sio);
return n;
@ -544,14 +439,8 @@ hawk_ooi_t hawk_sio_putbchars (hawk_sio_t* sio, const hawk_bch_t* str, hawk_oow_
#endif
LOCK_OUTPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_writebchars (&sio->tio.io, str, size);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_OUTPUT (sio);
return n;
}
@ -572,14 +461,14 @@ hawk_ooi_t hawk_sio_putucstr (hawk_sio_t* sio, const hawk_uch_t* str)
{
if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE)
{
sio->errnum = HAWK_SIO_ESYSERR;
hawk_gem_seterrnum (sio->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
if (count == 0) break;
if (count > left)
{
sio->errnum = HAWK_SIO_ESYSERR;
hawk_gem_seterrnum (sio->gem, HAWK_NULL, HAWK_ESYSERR);
return -1;
}
}
@ -589,9 +478,13 @@ hawk_ooi_t hawk_sio_putucstr (hawk_sio_t* sio, const hawk_uch_t* str)
if (sio->status & STATUS_LINE_BREAK)
{
LOCK_OUTPUT (sio);
for (n = 0; n < HAWK_TYPE_MAX(hawk_ooi_t) && str[n] != HAWK_UT('\0'); n++)
for (n = 0; n < HAWK_TYPE_MAX(hawk_ooi_t) && str[n] != '\0'; n++)
{
if (put_uchar_no_mutex(sio, str[n]) <= -1) return -1;
if (put_uchar_no_mutex(sio, str[n]) <= -1)
{
n = -1;
break;
}
}
UNLOCK_OUTPUT (sio);
return n;
@ -599,12 +492,7 @@ hawk_ooi_t hawk_sio_putucstr (hawk_sio_t* sio, const hawk_uch_t* str)
#endif
LOCK_OUTPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_writeuchars(&sio->tio.io, str, (hawk_oow_t)-1);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_OUTPUT (sio);
return n;
}
@ -637,7 +525,7 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_
{
if (WriteConsoleW(sio->file.handle, cur, left, &count, HAWK_NULL) == FALSE)
{
sio->errnum = HAWK_SIO_ESYSERR;
hawk_gem_seterrnum (sio->gem, HAWK_NULL, syserr_to_errnum(GetLastError()));
return -1;
}
if (count == 0) break;
@ -652,7 +540,7 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_
*/
if (count > left)
{
sio->errnum = HAWK_SIO_ESYSERR;
hawk_gem_seterrnum (sio->gem, HAWK_NULL, HAWK_ESYSERR);
return -1;
}
}
@ -666,7 +554,11 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_
LOCK_OUTPUT (sio);
for (n = 0; n < size; n++)
{
if (put_uchar_no_mutex(sio, str[n]) <= -1) return -1;
if (put_uchar_no_mutex(sio, str[n]) <= -1)
{
n = -1;
break;
}
}
UNLOCK_OUTPUT (sio);
return n;
@ -674,12 +566,7 @@ hawk_ooi_t hawk_sio_putuchars (hawk_sio_t* sio, const hawk_uch_t* str, hawk_oow_
#endif
LOCK_OUTPUT (sio);
sio->errnum = HAWK_SIO_ENOERR;
n = hawk_tio_writeuchars(&sio->tio.io, str, size);
if (n <= -1 && sio->errnum == HAWK_SIO_ENOERR)
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
UNLOCK_OUTPUT (sio);
return n;
}
@ -691,11 +578,7 @@ int hawk_sio_getpos (hawk_sio_t* sio, hawk_sio_pos_t* pos)
if (hawk_sio_flush(sio) <= -1) return -1;
off = hawk_fio_seek(&sio->file, 0, HAWK_FIO_CURRENT);
if (off == (hawk_fio_off_t)-1)
{
sio->errnum = fio_errnum_to_sio_errnum(&sio->file);
return -1;
}
if (off == (hawk_fio_off_t)-1) return -1;
*pos = off;
return 0;
@ -708,11 +591,7 @@ int hawk_sio_setpos (hawk_sio_t* sio, hawk_sio_pos_t pos)
if (hawk_sio_flush(sio) <= -1) return -1;
off = hawk_fio_seek(&sio->file, pos, HAWK_FIO_BEGIN);
if (off == (hawk_fio_off_t)-1)
{
sio->errnum = fio_errnum_to_sio_errnum(&sio->file);
return -1;
}
if (off == (hawk_fio_off_t)-1) return -1;
return 0;
}
@ -739,16 +618,13 @@ static hawk_ooi_t file_input (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, ha
{
if (cmd == HAWK_TIO_DATA)
{
hawk_ooi_t n;
hawk_sio_t* sio;
sio = *(hawk_sio_t**)(tio + 1);
HAWK_ASSERT (tio->hawk, sio != HAWK_NULL);
HAWK_ASSERT (tio->hawk, tio->hawk == sio->hawk);
/*HAWK_ASSERT (tio->hawk, sio != HAWK_NULL);
HAWK_ASSERT (tio->hawk, tio->hawk == sio->hawk);*/
n = hawk_fio_read(&sio->file, buf, size);
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
return n;
return hawk_fio_read(&sio->file, buf, size);
}
return 0;
@ -758,16 +634,13 @@ static hawk_ooi_t file_output (hawk_tio_t* tio, hawk_tio_cmd_t cmd, void* buf, h
{
if (cmd == HAWK_TIO_DATA)
{
hawk_ooi_t n;
hawk_sio_t* sio;
sio = *(hawk_sio_t**)(tio + 1);
HAWK_ASSERT (tio->hawk, sio != HAWK_NULL);
HAWK_ASSERT (tio->hawk, tio->hawk == sio->hawk);
/*HAWK_ASSERT (tio->hawk, sio != HAWK_NULL);
HAWK_ASSERT (tio->hawk, tio->hawk == sio->hawk);*/
n = hawk_fio_write(&sio->file, buf, size);
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum(&sio->file);
return n;
return hawk_fio_write(&sio->file, buf, size);
}
return 0;

View File

@ -137,6 +137,8 @@ typedef struct xtn_t
int gbl_argc;
int gbl_argv;
int gbl_environ;
int gbl_errno;
int gbl_errstr;
hawk_ecb_t ecb;
int stdmod_up;
@ -900,7 +902,7 @@ oops:
static hawk_sio_t* open_sio (hawk_t* awk, const hawk_ooch_t* file, int flags)
{
hawk_sio_t* sio;
sio = hawk_sio_open(awk, 0, file, flags);
sio = hawk_sio_open(hawk_getgem(awk), 0, file, flags);
if (sio == HAWK_NULL)
{
hawk_oocs_t errarg;
@ -914,7 +916,7 @@ static hawk_sio_t* open_sio (hawk_t* awk, const hawk_ooch_t* file, int flags)
static hawk_sio_t* open_sio_rtx (hawk_rtx_t* rtx, const hawk_ooch_t* file, int flags)
{
hawk_sio_t* sio;
sio = hawk_sio_open(hawk_rtx_gethawk(rtx), 0, file, flags);
sio = hawk_sio_open(hawk_rtx_getgem(rtx), 0, file, flags);
if (sio == HAWK_NULL)
{
hawk_oocs_t errarg;
@ -935,8 +937,12 @@ static hawk_oocs_t sio_std_names[] =
static hawk_sio_t* open_sio_std (hawk_t* awk, hawk_sio_std_t std, int flags)
{
hawk_sio_t* sio;
sio = hawk_sio_openstd(awk, 0, std, flags);
if (sio == HAWK_NULL) hawk_seterrnum (awk, HAWK_EOPEN, &sio_std_names[std]);
sio = hawk_sio_openstd(hawk_getgem(awk), 0, std, flags);
if (sio == HAWK_NULL)
{
const hawk_ooch_t* bem = hawk_backuperrmsg(awk);
hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", &sio_std_names[std], bem);
}
return sio;
}
@ -944,8 +950,12 @@ static hawk_sio_t* open_sio_std_rtx (hawk_rtx_t* rtx, hawk_sio_std_t std, int fl
{
hawk_sio_t* sio;
sio = hawk_sio_openstd(hawk_rtx_gethawk(rtx), 0, std, flags);
if (sio == HAWK_NULL) hawk_rtx_seterrnum (rtx, HAWK_EOPEN, &sio_std_names[std]);
sio = hawk_sio_openstd(hawk_rtx_getgem(rtx), 0, std, flags);
if (sio == HAWK_NULL)
{
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx);
hawk_rtx_seterrbfmt (rtx, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", &sio_std_names[std], bem);
}
return sio;
}
@ -1166,15 +1176,13 @@ static hawk_ooi_t sf_in_open (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn)
}
}
arg->handle = hawk_sio_open(awk, 0, path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
arg->handle = hawk_sio_open(hawk_getgem(awk), 0, path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
if (dbuf) hawk_freemem (awk, dbuf);
if (!arg->handle)
{
hawk_oocs_t ea;
ea.ptr = (hawk_ooch_t*)arg->name;
ea.len = hawk_count_oocstr(ea.ptr);
hawk_seterrnum (awk, HAWK_EOPEN, &ea);
const hawk_ooch_t* bem = hawk_backuperrmsg(awk);
hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", arg->name, bem);
return -1;
}
@ -1786,8 +1794,8 @@ static hawk_ooi_t pio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
return -1;
}
handle = hawk_pio_open (
hawk_rtx_gethawk(rtx),
handle = hawk_pio_open(
hawk_rtx_getgem(rtx),
0,
riod->name,
flags | HAWK_PIO_SHELL | HAWK_PIO_TEXT | HAWK_PIO_IGNOREECERR
@ -1936,13 +1944,11 @@ static hawk_ooi_t awk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_ar
return -1;
}
handle = hawk_sio_open(hawk_rtx_gethawk(rtx), 0, riod->name, flags);
handle = hawk_sio_open(hawk_rtx_getgem(rtx), 0, riod->name, flags);
if (handle == HAWK_NULL)
{
hawk_oocs_t errarg;
errarg.ptr = riod->name;
errarg.len = hawk_count_oocstr(riod->name);
hawk_rtx_seterrnum (rtx, HAWK_EOPEN, &errarg);
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx);
hawk_rtx_seterrbfmt (rtx, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", riod->name, bem);
return -1;
}
@ -2524,8 +2530,8 @@ static int build_environ (hawk_rtx_t* rtx, int gbl_id, env_char_t* envarr[])
static int make_additional_globals (hawk_rtx_t* rtx, xtn_t* xtn, const hawk_ooch_t* id, const hawk_ooch_t*const icf[])
{
if (build_argcv (rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 ||
build_environ (rtx, xtn->gbl_environ, environ) <= -1) return -1;
if (build_argcv(rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 ||
build_environ(rtx, xtn->gbl_environ, environ) <= -1) return -1;
return 0;
}
@ -3023,11 +3029,15 @@ static int add_globals (hawk_t* awk)
xtn->gbl_argc = hawk_addgbl(awk, HAWK_T("ARGC"));
xtn->gbl_argv = hawk_addgbl(awk, HAWK_T("ARGV"));
xtn->gbl_environ = hawk_addgbl(awk, HAWK_T("ENVIRON"));
xtn->gbl_environ = hawk_addgbl(awk, HAWK_T("ENVIRON"));
xtn->gbl_errno = hawk_addgbl(awk, HAWK_T("ERRNO"));
xtn->gbl_errstr = hawk_addgbl(awk, HAWK_T("ERRSTR"));
return (xtn->gbl_argc <= -1 ||
xtn->gbl_argv <= -1 ||
xtn->gbl_environ <= -1)? -1: 0;
xtn->gbl_environ <= -1 ||
xtn->gbl_errno <= -1 ||
xtn->gbl_errstr <= -1)? -1: 0;
}
struct fnctab_t

View File

@ -143,20 +143,22 @@
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case ENOMEM: return __SYSERRNUM__(obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__(obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case EPERM: return __SYSERRNUM__ (obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__ (obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
case EINPROGRESS: return __SYSERRNUM__ (obj2, EINPROG); \
case EACCES: return __SYSERRNUM__(obj2, EACCES); \
case EPERM: return __SYSERRNUM__(obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__(obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__(obj2, EEXIST); \
case EINTR: return __SYSERRNUM__(obj2, EINTR); \
case EPIPE: return __SYSERRNUM__(obj2, EPIPE); \
case ECHILD: return __SYSERRNUM__(obj2, ECHILD); \
case ETIMEDOUT: return __SYSERRNUM__(obj2, ETMOUT); \
case EINPROGRESS: return __SYSERRNUM__(obj2, EINPROG); \
case EWOULDBLOCK: \
case EAGAIN: return __SYSERRNUM__ (obj2, EAGAIN); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
case EAGAIN: return __SYSERRNUM__(obj2, EAGAIN); \
default: return __SYSERRNUM__(obj2, ESYSERR); \
} \
}
@ -167,19 +169,21 @@
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case ENOMEM: return __SYSERRNUM__(obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__(obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case EPERM: return __SYSERRNUM__ (obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__ (obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
case EINPROGRESS: return __SYSERRNUM__ (obj2, EINPROG); \
case EAGAIN: return __SYSERRNUM__ (obj2, EAGAIN); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
case EACCES: return __SYSERRNUM__(obj2, EACCES); \
case EPERM: return __SYSERRNUM__(obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__(obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__(obj2, EEXIST); \
case EINTR: return __SYSERRNUM__(obj2, EINTR); \
case EPIPE: return __SYSERRNUM__(obj2, EPIPE); \
case ECHILD: return __SYSERRNUM__(obj2, ECHILD); \
case ETIMEDOUT: return __SYSERRNUM__(obj2, ETMOUT); \
case EINPROGRESS: return __SYSERRNUM__(obj2, EINPROG); \
case EAGAIN: return __SYSERRNUM__(obj2, EAGAIN); \
default: return __SYSERRNUM__(obj2, ESYSERR); \
} \
}
@ -190,19 +194,21 @@
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case ENOMEM: return __SYSERRNUM__(obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__(obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case EPERM: return __SYSERRNUM__ (obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__ (obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
case EINPROGRESS: return __SYSERRNUM__ (obj2, EINPROG); \
case EWOULDBLOCK: return __SYSERRNUM__ (obj2, EAGAIN); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
case EACCES: return __SYSERRNUM__(obj2, EACCES); \
case EPERM: return __SYSERRNUM__(obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__(obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__(obj2, EEXIST); \
case EINTR: return __SYSERRNUM__(obj2, EINTR); \
case EPIPE: return __SYSERRNUM__(obj2, EPIPE); \
case ECHILD: return __SYSERRNUM__(obj2, ECHILD); \
case ETIMEDOUT: return __SYSERRNUM__(obj2, ETMOUT); \
case EINPROGRESS: return __SYSERRNUM__(obj2, EINPROG); \
case EWOULDBLOCK: return __SYSERRNUM__(obj2, EAGAIN); \
default: return __SYSERRNUM__(obj2, ESYSERR); \
} \
}
@ -213,18 +219,20 @@
{ \
switch (e) \
{ \
case ENOMEM: return __SYSERRNUM__ (obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__ (obj2, EINVAL); \
case ENOMEM: return __SYSERRNUM__(obj2, ENOMEM); \
case EINVAL: return __SYSERRNUM__(obj2, EINVAL); \
case EBUSY: \
case EACCES: return __SYSERRNUM__ (obj2, EACCES); \
case EPERM: return __SYSERRNUM__ (obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__ (obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__ (obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__ (obj2, EEXIST); \
case EINTR: return __SYSERRNUM__ (obj2, EINTR); \
case EPIPE: return __SYSERRNUM__ (obj2, EPIPE); \
case EINPROGRESS: return __SYSERRNUM__ (obj2, EINPROG); \
default: return __SYSERRNUM__ (obj2, ESYSERR); \
case EACCES: return __SYSERRNUM__(obj2, EACCES); \
case EPERM: return __SYSERRNUM__(obj2, EPERM); \
case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \
case ENOENT: return __SYSERRNUM__(obj2, ENOENT); \
case EEXIST: return __SYSERRNUM__(obj2, EEXIST); \
case EINTR: return __SYSERRNUM__(obj2, EINTR); \
case EPIPE: return __SYSERRNUM__(obj2, EPIPE); \
case ECHILD: return __SYSERRNUM__(obj2, ECHILD); \
case ETIMEDOUT: return __SYSERRNUM__(obj2, ETMOUT); \
case EINPROGRESS: return __SYSERRNUM__(obj2, EINPROG); \
default: return __SYSERRNUM__(obj2, ESYSERR); \
} \
}

View File

@ -35,16 +35,16 @@
static int detach_in (hawk_tio_t* tio, int fini);
static int detach_out (hawk_tio_t* tio, int fini);
hawk_tio_t* hawk_tio_open (hawk_t* hawk, hawk_oow_t xtnsize, int flags)
hawk_tio_t* hawk_tio_open (hawk_gem_t* gem, hawk_oow_t xtnsize, int flags)
{
hawk_tio_t* tio;
tio = (hawk_tio_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_tio_t) + xtnsize);
tio = (hawk_tio_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_tio_t) + xtnsize);
if (tio)
{
if (hawk_tio_init(tio, hawk, flags) <= -1)
if (hawk_tio_init(tio, gem, flags) <= -1)
{
hawk_freemem (hawk, tio);
hawk_gem_freemem (gem, tio);
return HAWK_NULL;
}
else HAWK_MEMSET (tio + 1, 0, xtnsize);
@ -55,16 +55,16 @@ hawk_tio_t* hawk_tio_open (hawk_t* hawk, hawk_oow_t xtnsize, int flags)
int hawk_tio_close (hawk_tio_t* tio)
{
int n = hawk_tio_fini(tio);
hawk_freemem (tio->hawk, tio);
hawk_gem_freemem (tio->gem, tio);
return n;
}
int hawk_tio_init (hawk_tio_t* tio, hawk_t* hawk, int flags)
int hawk_tio_init (hawk_tio_t* tio, hawk_gem_t* gem, int flags)
{
HAWK_MEMSET (tio, 0, HAWK_SIZEOF(*tio));
tio->hawk = hawk;
tio->cmgr = hawk_getcmgr(hawk);
tio->gem = gem;
tio->cmgr = gem->cmgr;
tio->flags = flags;
@ -79,8 +79,6 @@ int hawk_tio_init (hawk_tio_t* tio, hawk_t* hawk, int flags)
tio->inbuf_len = 0;
tio->outbuf_len = 0;
*/
tio->errnum = HAWK_TIO_ENOERR;
return 0;
}
@ -95,17 +93,6 @@ int hawk_tio_fini (hawk_tio_t* tio)
return ret;
}
hawk_tio_errnum_t hawk_tio_geterrnum (const hawk_tio_t* tio)
{
return tio->errnum;
}
void hawk_tio_seterrnum (hawk_tio_t* tio, hawk_tio_errnum_t errnum)
{
tio->errnum = errnum;
}
hawk_cmgr_t* hawk_tio_getcmgr (hawk_tio_t* tio)
{
return tio->cmgr;
@ -124,7 +111,7 @@ int hawk_tio_attachin (
if (input == HAWK_NULL || bufcapa < HAWK_TIO_MININBUFCAPA)
{
tio->errnum = HAWK_TIO_EINVAL;
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -135,19 +122,13 @@ int hawk_tio_attachin (
xbufptr = bufptr;
if (xbufptr == HAWK_NULL)
{
xbufptr = hawk_allocmem(tio->hawk, HAWK_SIZEOF(hawk_bch_t) * bufcapa);
if (xbufptr == HAWK_NULL)
{
tio->errnum = HAWK_TIO_ENOMEM;
return -1;
}
xbufptr = hawk_gem_allocmem(tio->gem, HAWK_SIZEOF(hawk_bch_t) * bufcapa);
if (xbufptr == HAWK_NULL) return -1;
}
tio->errnum = HAWK_TIO_ENOERR;
if (input(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
if (xbufptr != bufptr) hawk_freemem (tio->hawk, xbufptr);
if (xbufptr != bufptr) hawk_gem_freemem (tio->gem, xbufptr);
return -1;
}
@ -176,11 +157,8 @@ static int detach_in (hawk_tio_t* tio, int fini)
if (tio->in.fun)
{
tio->errnum = HAWK_TIO_ENOERR;
if (tio->in.fun(tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
/* returning with an error here allows you to retry detaching */
if (!fini) return -1;
@ -191,7 +169,7 @@ static int detach_in (hawk_tio_t* tio, int fini)
if (tio->status & STATUS_INPUT_DYNBUF)
{
hawk_freemem(tio->hawk, tio->in.buf.ptr);
hawk_gem_freemem(tio->gem, tio->in.buf.ptr);
tio->status &= ~STATUS_INPUT_DYNBUF;
}
@ -216,30 +194,24 @@ int hawk_tio_attachout (
if (output == HAWK_NULL || bufcapa < HAWK_TIO_MINOUTBUFCAPA)
{
tio->errnum = HAWK_TIO_EINVAL;
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL);
return -1;
}
if (hawk_tio_detachout(tio) == -1) return -1;
HAWK_ASSERT (tio->hawk, tio->out.fun == HAWK_NULL);
/*HAWK_ASSERT (tio->hawk, tio->out.fun == HAWK_NULL);*/
xbufptr = bufptr;
if (xbufptr == HAWK_NULL)
{
xbufptr = hawk_allocmem(tio->hawk, HAWK_SIZEOF(hawk_bch_t) * bufcapa);
if (xbufptr == HAWK_NULL)
{
tio->errnum = HAWK_TIO_ENOMEM;
return -1;
}
xbufptr = hawk_gem_allocmem(tio->gem, HAWK_SIZEOF(hawk_bch_t) * bufcapa);
if (xbufptr == HAWK_NULL) return -1;
}
tio->errnum = HAWK_TIO_ENOERR;
if (output(tio, HAWK_TIO_OPEN, HAWK_NULL, 0) <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
if (xbufptr != bufptr) hawk_freemem (tio->hawk, xbufptr);
if (xbufptr != bufptr) hawk_gem_freemem (tio->gem, xbufptr);
return -1;
}
@ -261,10 +233,8 @@ static int detach_out (hawk_tio_t* tio, int fini)
{
hawk_tio_flush (tio); /* don't care about the result */
tio->errnum = HAWK_TIO_ENOERR;
if (tio->out.fun (tio, HAWK_TIO_CLOSE, HAWK_NULL, 0) <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
/* returning with an error here allows you to retry detaching */
if (!fini) return -1;
@ -275,7 +245,7 @@ static int detach_out (hawk_tio_t* tio, int fini)
if (tio->status & STATUS_OUTPUT_DYNBUF)
{
hawk_freemem (tio->hawk, tio->out.buf.ptr);
hawk_gem_freemem (tio->gem, tio->out.buf.ptr);
tio->status &= ~STATUS_OUTPUT_DYNBUF;
}
@ -283,13 +253,13 @@ static int detach_out (hawk_tio_t* tio, int fini)
tio->out.buf.ptr = HAWK_NULL;
tio->out.buf.capa = 0;
}
return ret;
}
int hawk_tio_detachout (hawk_tio_t* tio)
{
return detach_out (tio, 0);
return detach_out(tio, 0);
}
hawk_ooi_t hawk_tio_flush (hawk_tio_t* tio)
@ -300,7 +270,8 @@ hawk_ooi_t hawk_tio_flush (hawk_tio_t* tio)
if (tio->out.fun == HAWK_NULL)
{
tio->errnum = HAWK_TIO_ENOUTF;
/* no output function */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL);
return (hawk_ooi_t)-1;
}
@ -308,11 +279,9 @@ hawk_ooi_t hawk_tio_flush (hawk_tio_t* tio)
cur = tio->out.buf.ptr;
while (left > 0)
{
tio->errnum = HAWK_TIO_ENOERR;
n = tio->out.fun (tio, HAWK_TIO_DATA, cur, left);
n = tio->out.fun(tio, HAWK_TIO_DATA, cur, left);
if (n <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
if (cur != tio->out.buf.ptr)
{
HAWK_MEMCPY (tio->out.buf.ptr, cur, left);
@ -343,7 +312,6 @@ void hawk_tio_drain (hawk_tio_t* tio)
tio->inbuf_cur = 0;
tio->inbuf_len = 0;
tio->outbuf_len = 0;
tio->errnum = HAWK_TIO_ENOERR;
}
/* ------------------------------------------------------------- */
@ -357,7 +325,8 @@ hawk_ooi_t hawk_tio_readbchars (hawk_tio_t* tio, hawk_bch_t* buf, hawk_oow_t siz
/*HAWK_ASSERT (tio->hawk, tio->in.fun != HAWK_NULL);*/
if (tio->in.fun == HAWK_NULL)
{
tio->errnum = HAWK_TIO_ENINPF;
/* no input function */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -373,16 +342,9 @@ hawk_ooi_t hawk_tio_readbchars (hawk_tio_t* tio, hawk_bch_t* buf, hawk_oow_t siz
{
if (tio->inbuf_cur >= tio->inbuf_len)
{
tio->errnum = HAWK_TIO_ENOERR;
n = tio->in.fun (
tio, HAWK_TIO_DATA,
tio->in.buf.ptr, tio->in.buf.capa);
n = tio->in.fun(tio, HAWK_TIO_DATA, tio->in.buf.ptr, tio->in.buf.capa);
if (n == 0) break;
if (n <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
return -1;
}
if (n <= -1) return -1;
tio->inbuf_cur = 0;
tio->inbuf_len = (hawk_oow_t)n;
@ -401,7 +363,7 @@ done:
return nread;
}
static HAWK_INLINE hawk_ooi_t tio_read_widechars (
static HAWK_INLINE hawk_ooi_t tio_read_uchars (
hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t bufsize)
{
hawk_oow_t mlen, wlen;
@ -417,11 +379,7 @@ static HAWK_INLINE hawk_ooi_t tio_read_widechars (
if (tio->status & STATUS_INPUT_EOF) n = 0;
else
{
tio->errnum = HAWK_TIO_ENOERR;
n = tio->in.fun (
tio, HAWK_TIO_DATA,
&tio->in.buf.ptr[tio->inbuf_len],
tio->in.buf.capa - tio->inbuf_len);
n = tio->in.fun(tio, HAWK_TIO_DATA, &tio->in.buf.ptr[tio->inbuf_len], tio->in.buf.capa - tio->inbuf_len);
}
if (n == 0)
{
@ -433,23 +391,19 @@ static HAWK_INLINE hawk_ooi_t tio_read_widechars (
* but some incomplete bytes in the buffer. */
if (tio->flags & HAWK_TIO_IGNOREECERR)
{
/* tread them as illegal sequence */
goto ignore_illseq;
}
else
{
tio->errnum = HAWK_TIO_EICSEQ;
/* treat them as illegal sequence */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EECERR);
return -1;
}
}
return 0;
}
if (n <= -1)
{
if (tio->errnum == HAWK_TIO_ENOERR) tio->errnum = HAWK_TIO_EOTHER;
return -1;
}
if (n <= -1) return -1;
tio->inbuf_len += n;
}
@ -501,7 +455,8 @@ static HAWK_INLINE hawk_ooi_t tio_read_widechars (
}
else if (wlen <= 0)
{
tio->errnum = HAWK_TIO_EILSEQ;
/* really illegal sequence */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EECERR);
return -1;
}
else
@ -524,7 +479,8 @@ hawk_ooi_t hawk_tio_readuchars (hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t siz
/*HAWK_ASSERT (tio->hawk, tio->in.fun != HAWK_NULL);*/
if (tio->in.fun == HAWK_NULL)
{
tio->errnum = HAWK_TIO_ENINPF;
/* no input handler function */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -535,11 +491,11 @@ hawk_ooi_t hawk_tio_readuchars (hawk_tio_t* tio, hawk_uch_t* buf, hawk_oow_t siz
if (tio->status & STATUS_INPUT_ILLSEQ)
{
tio->status &= ~STATUS_INPUT_ILLSEQ;
tio->errnum = HAWK_TIO_EILSEQ;
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EECERR);
return -1;
}
n = tio_read_widechars (tio, &buf[nread], size - nread);
n = tio_read_uchars(tio, &buf[nread], size - nread);
if (n == 0) break;
if (n <= -1) return -1;
@ -559,7 +515,7 @@ hawk_ooi_t hawk_tio_writebchars (hawk_tio_t* tio, const hawk_bch_t* mptr, hawk_o
/* maybe, previous flush operation has failed a few
* times previously. so the buffer is full.
*/
tio->errnum = HAWK_TIO_ENOSPC;
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EBUFFULL);
return -1;
}
@ -660,7 +616,7 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o
{
/* maybe, previous flush operation has failed a few
* times previously. so the buffer is full. */
tio->errnum = HAWK_TIO_ENOSPC;
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EBUFFULL);
return -1;
}
@ -710,7 +666,8 @@ hawk_ooi_t hawk_tio_writeuchars (hawk_tio_t* tio, const hawk_uch_t* wptr, hawk_o
}
else
{
tio->errnum = HAWK_TIO_EILCHR;
/* illegal character */
hawk_gem_seterrnum (tio->gem, HAWK_NULL, HAWK_EECERR);
return -1;
}
}

View File

@ -29,9 +29,9 @@
#if defined(_WIN32)
# include <windows.h>
# include <time.h>
# define EPOCH_DIFF_YEARS (HAWK_EPOCH_YEAR-HAWK_EPOCH_YEAR_WIN)
# define EPOCH_DIFF_DAYS ((hawk_intptr_t)EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
# define EPOCH_DIFF_SECS ((hawk_intptr_t)EPOCH_DIFF_DAYS*24*60*60)
# define EPOCH_DIFF_YEARS (HAWK_EPOCH_YEAR - HAWK_EPOCH_YEAR_WIN)
# define EPOCH_DIFF_DAYS ((hawk_intptr_t)EPOCH_DIFF_YEARS * 365 + EPOCH_DIFF_YEARS / 4 - 3)
# define EPOCH_DIFF_SECS ((hawk_intptr_t)EPOCH_DIFF_DAYS * 24 * 60 * 60)
#elif defined(__OS2__)
# define INCL_DOSDATETIME
# define INCL_DOSERRORS