From 308d806145a70dc23c0a4430e3f4d9dd3f733750 Mon Sep 17 00:00:00 2001 From: vsfos Date: Fri, 8 Sep 2023 17:28:30 +0800 Subject: [PATCH] [component/python/os] add chdir and os.name --- .../script/python/module/os/vsf_python_module_os.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/component/script/python/module/os/vsf_python_module_os.c b/source/component/script/python/module/os/vsf_python_module_os.c index ffbd9f63e..a2056ac18 100644 --- a/source/component/script/python/module/os/vsf_python_module_os.c +++ b/source/component/script/python/module/os/vsf_python_module_os.c @@ -65,6 +65,10 @@ vsf_pyal_module_func_init_imp(os) vsf_pyal_module_add_int(os, "O_APPEND", O_APPEND); vsf_pyal_module_add_int(os, "O_CREAT", O_CREAT); + struct utsname name; + uname(&utsname); + vsf_pyal_module_add_str(os, "name", name.sysname); + environ_dict = vsf_pyal_newdict(); vsf_pyal_module_add_obj(os, "environ", environ_dict); #else @@ -181,6 +185,15 @@ vsf_pyal_module_func_fix_imp(os, rmdir, VSF_PYAL_MODULE_FUNCARG_OBJ_1, vsf_pyal_ vsf_pyal_func_void_return(); } +vsf_pyal_module_func_fix_imp(os, chdir, VSF_PYAL_MODULE_FUNCARG_OBJ_1, vsf_pyal_func_void_return_t, vsf_pyal_funcarg_strobj path) +{ + char *path_str = vsf_pyal_funcarg_strobj_get_str(path); + if (chdir((const char *)path_str) < 0) { + vsf_pyal_raise("fail to chdir(%s)\n", path_str); + } + vsf_pyal_func_void_return(); +} + vsf_pyal_module_func_fix_imp(os, rename, VSF_PYAL_MODULE_FUNCARG_OBJ_2, vsf_pyal_func_void_return_t, vsf_pyal_funcarg_strobj old, vsf_pyal_funcarg_strobj new) { char *path_old_str = vsf_pyal_funcarg_strobj_get_str(old); @@ -360,6 +373,7 @@ vsf_pyal_module(os, vsf_pyal_module_func(os, mkdir), vsf_pyal_module_func(os, makedirs), vsf_pyal_module_func(os, rmdir), + vsf_pyal_module_func(os, chdir), vsf_pyal_module_func(os, rename), vsf_pyal_module_func(os, remove), vsf_pyal_module_func(os, open),