From c1540a5e93f0822d0572c3c357285ed6f1fabe7d Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Tue, 31 Oct 2023 16:21:31 +0800 Subject: [PATCH] add assoc_insert func for assoc file --- bash-5.1/r_assoc/src/lib.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bash-5.1/r_assoc/src/lib.rs b/bash-5.1/r_assoc/src/lib.rs index 7ee4bb65..1ee37ef9 100644 --- a/bash-5.1/r_assoc/src/lib.rs +++ b/bash-5.1/r_assoc/src/lib.rs @@ -28,4 +28,42 @@ macro_rules! ALL_ELEMENT_SUB { } } +#[no_mangle] +pub unsafe extern "C" fn assoc_dispose(mut hash: *mut HASH_TABLE) { + if !hash.is_null() { + hash_flush(hash, None); + hash_dispose(hash); + } +} + +#[no_mangle] +pub unsafe extern "C" fn assoc_flush(mut hash: *mut HASH_TABLE) { + hash_flush(hash, None); +} +#[no_mangle] +pub unsafe extern "C" fn assoc_insert( + mut hash: *mut HASH_TABLE, + mut key: *mut libc::c_char, + mut value: *mut libc::c_char, +) -> libc::c_int { + let mut b: *mut BUCKET_CONTENTS = 0 as *mut BUCKET_CONTENTS; + b = hash_search(key, hash, 0x2 as libc::c_int); + if b.is_null() { + return -(1 as libc::c_int); + } + if (*b).key != key { + libc::free(key as *mut libc::c_void); + } + if !((*b).data).is_null() { + libc::free((*b).data); + } + (*b).data = 0 as *mut libc::c_void; + (*b) + .data = (if !value.is_null() { + savestring!(value) + } else { + 0 as *mut libc::c_char + }) as *mut libc::c_void; + return 0 as libc::c_int; +} -- Gitee