some code touch up in mod-sys.c

This commit is contained in:
hyung-hwan 2020-01-10 08:28:52 +00:00
parent ca1c6cf97f
commit 8f484cf79e

View File

@ -1884,7 +1884,7 @@ static int fnc_getenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
hawk_bch_t* val; hawk_bch_t* val;
if (hawk_rfind_bchar(var, len, '\0')) if (hawk_find_bchar(var, len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_freevalbcstr (rtx, a0, var); hawk_rtx_freevalbcstr (rtx, a0, var);
@ -1947,8 +1947,8 @@ static int fnc_setenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
} }
/* the target name contains a null character. */ /* the target name contains a null character. */
if (hawk_rfind_bchar(var, var_len, '\0') || if (hawk_find_bchar(var, var_len, '\0') ||
hawk_rfind_bchar(val, val_len, '\0')) hawk_find_bchar(val, val_len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done; goto done;
@ -1988,7 +1988,7 @@ static int fnc_unsetenv (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
} }
/* the target name contains a null character. */ /* the target name contains a null character. */
if (hawk_rfind_bchar(str, len, '\0')) if (hawk_find_bchar(str, len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done; goto done;
@ -2130,7 +2130,7 @@ static int fnc_system (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
} }
/* the target name contains a null character. make system return -1 */ /* the target name contains a null character. make system return -1 */
if (hawk_rfind_oochar(str, len, '\0')) if (hawk_find_oochar(str, len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done; goto done;
@ -2175,59 +2175,44 @@ static int fnc_chroot (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
sys_list_t* sys_list; sys_list_t* sys_list;
hawk_val_t* a0; hawk_val_t* a0;
hawk_ooch_t* str;
hawk_oow_t len;
hawk_int_t rx; hawk_int_t rx;
sys_list = rtx_to_sys_list(rtx, fi); sys_list = rtx_to_sys_list(rtx, fi);
a0 = hawk_rtx_getarg(rtx, 0); a0 = hawk_rtx_getarg(rtx, 0);
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
if (!str)
{
rx = copy_error_to_sys_list(rtx, sys_list);
goto done;
}
/* the target name contains a null character. make system return -1 */
if (hawk_rfind_oochar(str, len, '\0'))
{
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done;
}
#if defined(_WIN32) #if defined(_WIN32)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(__OS2__) #elif defined(__OS2__)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(__DOS__) #elif defined(__DOS__)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(HAWK_OOCH_IS_BCH)
rx = HAWK_CHROOT(str, mode);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
#else #else
{ {
hawk_bch_t* mbs; hawk_bch_t* str;
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL); hawk_oow_t len;
if (mbs)
{ str = hawk_rtx_getvalbcstr(rtx, a0, &len);
rx = HAWK_CHROOT(mbs); if (!str)
hawk_rtx_freemem (rtx, mbs);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
}
else
{ {
rx = copy_error_to_sys_list(rtx, sys_list); rx = copy_error_to_sys_list(rtx, sys_list);
goto done;
} }
/* the target name contains a null character. */
if (hawk_find_bchar(str, len, '\0'))
{
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done;
}
rx = HAWK_CHROOT(str);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
done:
if (str) hawk_rtx_freevalbcstr (rtx, a0, str);
} }
#endif #endif
done:
if (str) hawk_rtx_freevaloocstr (rtx, a0, str);
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx)); HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx)); hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
return 0; return 0;
@ -2255,7 +2240,7 @@ static int fnc_chmod (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
} }
/* the target name contains a null character. make system return -1 */ /* the target name contains a null character. make system return -1 */
if (hawk_rfind_oochar(str, len, '\0')) if (hawk_find_oochar(str, len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done; goto done;
@ -2314,7 +2299,7 @@ static int fnc_mkdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
} }
/* the target name contains a null character. */ /* the target name contains a null character. */
if (hawk_rfind_oochar(str, len, '\0')) if (hawk_find_oochar(str, len, '\0'))
{ {
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done; goto done;
@ -2357,59 +2342,42 @@ static int fnc_unlink (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
sys_list_t* sys_list; sys_list_t* sys_list;
hawk_val_t* a0; hawk_val_t* a0;
hawk_ooch_t* str;
hawk_oow_t len;
hawk_int_t rx; hawk_int_t rx;
sys_list = rtx_to_sys_list(rtx, fi); sys_list = rtx_to_sys_list(rtx, fi);
a0 = hawk_rtx_getarg(rtx, 0); a0 = hawk_rtx_getarg(rtx, 0);
str = hawk_rtx_getvaloocstr(rtx, a0, &len);
if (!str)
{
rx = copy_error_to_sys_list(rtx, sys_list);
goto done;
}
/* the target name contains a null character. make system return -1 */
if (hawk_rfind_oochar(str, len, '\0'))
{
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done;
}
#if defined(_WIN32) #if defined(_WIN32)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(__OS2__) #elif defined(__OS2__)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(__DOS__)
/* TOOD: implement this*/
rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL);
#elif defined(HAWK_OOCH_IS_BCH)
rx = HAWK_UNLINK(str);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
#else #else
{ {
hawk_bch_t* mbs; hawk_bch_t* str;
mbs = hawk_rtx_duputobcstr(rtx, str, HAWK_NULL); hawk_oow_t len;
if (mbs)
{ str = hawk_rtx_getvalbcstr(rtx, a0, &len);
rx = HAWK_UNLINK(mbs); if (!str)
hawk_rtx_freemem (rtx, mbs);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
}
else
{ {
rx = copy_error_to_sys_list(rtx, sys_list); rx = copy_error_to_sys_list(rtx, sys_list);
goto done;
} }
/* the target name contains a null character. */
if (hawk_find_bchar(str, len, '\0'))
{
rx = set_error_on_sys_list(rtx, sys_list, HAWK_EINVAL, HAWK_NULL);
goto done;
}
rx = HAWK_UNLINK(str);
if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL);
done:
if (str) hawk_rtx_freevalbcstr (rtx, a0, str);
} }
#endif #endif
done:
if (str) hawk_rtx_freevaloocstr (rtx, a0, str);
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx)); HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(rx));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx)); hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx));
return 0; return 0;