diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index cb0e1fede3d3b90135e2fd865a6ca66b5cb7ca6c..d4364a959b28d268f99833fa01f687f465cc633b 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); + } +} +