Added sys::sockaddrdom()

This commit is contained in:
hyung-hwan 2020-03-02 09:40:40 +00:00
parent 48809c9e69
commit 8753eae27a

View File

@ -716,8 +716,8 @@ static int fnc_write (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
hawk_ooi_t startpos = 0, maxlen = HAWK_TYPE_MAX(hawk_ooi_t);
hawk_val_t* a1;
if (hawk_rtx_getnargs(rtx) >= 3 && hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &startpos) <= -1 || startpos < 0) startpos = 0;
else if (startpos > 1) startpos--; /* this position is 1-based */
if (hawk_rtx_getnargs(rtx) >= 3 && (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &startpos) <= -1 || startpos < 0)) startpos = 0;
else if (startpos > 0) startpos--; /* this position is 1-based */
if (hawk_rtx_getnargs(rtx) >= 4 && hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 3), &maxlen) <= -1) maxlen = HAWK_TYPE_MAX(hawk_ooi_t);
else if (maxlen < 0) maxlen = 0;
@ -3368,6 +3368,42 @@ done:
/* ------------------------------------------------------------ */
static int fnc_sockaddrdom (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
sys_list_t* sys_list;
hawk_val_t* a0;
hawk_ooch_t* addr;
hawk_oow_t len;
hawk_skad_t skad;
hawk_int_t rx;
sys_list = rtx_to_sys_list(rtx, fi);
a0 = hawk_rtx_getarg(rtx, 0);
addr = hawk_rtx_getvaloocstr(rtx, a0, &len);
if (addr)
{
if (hawk_gem_oocharstoskad(hawk_rtx_getgem(rtx), addr, len, &skad) <= -1)
{
rx = copy_error_to_sys_list(rtx, sys_list);
}
else
{
rx = hawk_skad_family(&skad);
}
hawk_rtx_freevaloocstr (rtx, a0, addr);
}
else
{
rx = copy_error_to_sys_list(rtx, sys_list);
}
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
return 0;
}
static int fnc_socket (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
sys_list_t* sys_list;
@ -4282,6 +4318,7 @@ static fnctab_t fnctab[] =
{ HAWK_T("settime"), { { 1, 1, HAWK_NULL }, fnc_settime, 0 } },
{ HAWK_T("shutdown"), { { 2, 2, HAWK_NULL }, fnc_shutdown, 0 } },
{ HAWK_T("sleep"), { { 1, 1, HAWK_NULL }, fnc_sleep, 0 } },
{ HAWK_T("sockaddrdom"), { { 1, 1, HAWK_NULL }, fnc_sockaddrdom, 0 } },
{ HAWK_T("socket"), { { 3, 3, HAWK_NULL }, fnc_socket, 0 } },
{ HAWK_T("strftime"), { { 2, 3, HAWK_NULL }, fnc_strftime, 0 } },
{ HAWK_T("symlink"), { { 2, 2, HAWK_NULL }, fnc_symlink, 0 } },