From 4af84225403336cf5c8effbc601f11607cdfaa5c Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Wed, 11 Oct 2023 15:22:03 +0800 Subject: [PATCH] add func set_machine_vars and sh_get_home_dir --- bash-5.1/r_variables/src/lib.rs | 56 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index d4364a9..48a28fa 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -167,6 +167,33 @@ unsafe extern "C" fn create_variable_tables() { } } +unsafe extern "C" fn set_machine_vars() { + + let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; + //set_if_not 下文会实现 + temp_var = set_if_not( + b"HOSTTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_host_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"OSTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_os_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"MACHTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_mach_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"HOSTNAME\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + current_host_name + ); + + +} + #[no_mangle] pub unsafe extern "C" fn sh_get_home_dir() -> *mut libc::c_char { @@ -176,32 +203,3 @@ pub unsafe extern "C" fn sh_get_home_dir() -> *mut libc::c_char { } 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