1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB 1998-2016. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 *
20
21 */
22 #include <stdlib.h>
23 #include "reg.h"
24
ei_reg_setpval(ei_reg * reg,const char * key,const void * p,int size)25 int ei_reg_setpval(ei_reg *reg, const char *key, const void *p, int size)
26 {
27 ei_hash *tab;
28 ei_reg_obj *obj=NULL;
29
30 if (size < 0) return -1;
31 if (!key || !reg) return -1; /* return EI_BADARG; */
32 tab = reg->tab;
33
34 if ((obj=ei_hash_lookup(tab,key))) {
35 /* object with same name already exists */
36 switch (ei_reg_typeof(obj)) {
37 case EI_INT:
38 break;
39 case EI_FLT:
40 break;
41 case EI_STR:
42 if (obj->size > 0) free(obj->val.s);
43 break;
44 case EI_BIN:
45 if (obj->size > 0) free(obj->val.p);
46 break;
47 default:
48 return -1;
49 /* return EI_UNKNOWN; */
50 }
51 }
52 else {
53 /* object is new */
54 if (!(obj=ei_reg_make(reg,EI_BIN))) return -1; /* return EI_NOMEM; */
55 ei_hash_insert(tab,key,obj);
56 }
57
58 obj->attr = EI_BIN | EI_DIRTY;
59 obj->val.p=(void *)p;
60 obj->size=size;
61
62 return 0;
63 }
64