1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| struct KVNode; typedef struct KVNode { struct *next; const char *key; void *value; int lenth; } KVNode;
typedef struct Object{ Object_Mtable *mtable; KVNode *head; };
void set_kv(Object *o, const char *name,void *value, int length){ KVNode *node = o -> head; while(node != NULL){ if(strcmp(name,node->key) == 0){ memcpy(node->value,value,length); return; } if(node -> next == NULL){ KVNode *new_node = malloc(typeof(KVNode)); new_code->name = malloc(strlen(name)+1); memcpy(new_node->name,name,strlen(name)+1); new_code->value = malloc(length); memcpy(new_code->value.value,length); new_code->length = length; node->next = new_code; return; } node = node->next; } }
|