From b3ebe34807befb9e28d878e29fc58de893ab44fe Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Tue, 10 Oct 2023 15:46:30 +0800 Subject: [PATCH] realize func set_home_var sh_get_home_dir set_shell_var --- bash-5.1/r_variables/src/lib.rs | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index cb0e1fe..d4364a9 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -166,3 +166,42 @@ unsafe extern "C" fn create_variable_tables() { shell_function_defs = hash_create(FUNCTIONS_HASH_BUCKETS!() as libc::c_int); } } + +#[no_mangle] +pub unsafe extern "C" fn sh_get_home_dir() -> *mut libc::c_char { + + if (current_user.home_dir).is_null() { + // get_current_user_info in file of shell.c + get_current_user_info(); + } + return current_user.home_dir; +} + +unsafe extern "C" fn set_home_var() { + let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; + // find_variable 下文会实现 + temp_var = find_variable(b"HOME\0" as *const u8 as *const libc::c_char); + if temp_var.is_null() { + temp_var =bind_variable( + b"HOME\0" as *const u8 as *const libc::c_char, + sh_get_home_dir(), + 0 as libc::c_int); + } +} + +unsafe extern "C" fn set_shell_var() { + let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; + // find_variable 下文会实现 + temp_var = find_variable(b"SHELL\0" as *const u8 as *const libc::c_char); + if temp_var.is_null() { + if (current_user.shell).is_null() { + // get_current_user_info in file of shell.c + get_current_user_info(); + } + temp_var =bind_variable( + b"SHELL\0" as *const u8 as *const libc::c_char, + current_user.shell, + 0 as libc::c_int); + } +} + -- Gitee