TA端实现调用增删改查功能
static TEE_Result Insert_key_value(linkedList list,uint32_t param_types,TEE_Param params[4]){ uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); DMSG("has been called"); if (param_types != exp_param_types) return TEE_ERROR_BAD_PARAMETERS; ElemType key=0; ElemType value=0; key=params[0].value.a; value=params[0].value.b; linkedListInsert(list,key,value); IMSG("Insert Key and Value Success!!n"); return TEE_SUCCESS; } static TEE_Result Edit_key_value(linkedList list,uint32_t param_types,TEE_Param params[4]){ uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); DMSG("has been called"); if (param_types != exp_param_types) return TEE_ERROR_BAD_PARAMETERS; ElemType key=0; ElemType value=0; key=params[0].value.a; value=params[0].value.b; linkedListEdit(list,key,value); IMSG("Edit Successn"); return TEE_SUCCESS; } static TEE_Result Select_key_value(linkedList list,uint32_t param_types,TEE_Param params[4]){ uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); DMSG("has been called"); if (param_types != exp_param_types) return TEE_ERROR_BAD_PARAMETERS; ElemType key=0; ElemType value=0; key=params[0].value.a; value=linkedListSelect(list,key); params[0].value.b=value; return TEE_SUCCESS; } static TEE_Result Delete_key_value(linkedList list,uint32_t param_types,TEE_Param params[4]){ uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); DMSG("has been called"); if (param_types != exp_param_types) return TEE_ERROR_BAD_PARAMETERS; ElemType key=0; key=params[0].value.a; linkedListDelete(list,key); IMSG("Delete Successn"); return TEE_SUCCESS; }
TA端中实现增删改查的功能函数
linkedList linkedListInit() { Node *L; L = (Node *)malloc(sizeof(Node)); //申请结点空间 if(L == NULL) //判断是否有足够的内存空间 printf("申请内存空间失败n"); L->next = NULL; //将next设置为NULL,初始长度为0的单链表 } //单链表的插入,在链表的第i个位置插入x的元素 linkedList linkedListInsert(linkedList L,ElemType key,ElemType value) { Node *pre; //pre为前驱结点 pre = L; //查找第i个位置的前驱结点 while(pre->next!=NULL){ pre=pre->next; } Node *p; //插入的结点为p p = (Node *)malloc(sizeof(Node)); p->key = key; p->value=value; p->next = pre->next; pre->next = p; return L; } //单链表的修改,在链表修改值为x的元素 linkedList linkedListEdit(linkedList L,ElemType x,ElemType value) { Node *p,*pre; //pre为前驱结点,p为查找的结点。 p = L->next; while(p->key != x) //查找值为x的元素 { pre = p; p = p->next; } p->value=value; return L; } ElemType linkedListSelect(linkedList L,ElemType x) { Node *p,*pre; //pre为前驱结点,p为查找的结点。 p = L->next; while(p->key != x) //查找值为x的元素 { pre = p; p = p->next; } return p->value; } / //单链表的删除,在链表中删除值为x的元素 linkedList linkedListDelete(linkedList L,ElemType x) { Node *p,*pre; pre=L; if(pre->key==x){ pre=pre->next; return L; } //pre为前驱结点,p为查找的结点。 p = L->next; while(p->key != x) //查找值为x的元素 { pre = p; p = p->next; } pre->next = p->next; //删除 *** 作,将其前驱next指向其后继。 free(p); return L; } /
资源下载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)