Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Iniparser
提交
beb67e38
T
Third Party Iniparser
项目概览
OpenHarmony
/
Third Party Iniparser
大约 1 年 前同步成功
通知
0
Star
24
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Iniparser
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
beb67e38
编写于
9月 12, 2013
作者:
N
Nicolas D
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17 from Foxtacles/upstream
Contributions by rmartinjak
上级
a8d6e6bf
d7e4600c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
21 deletion
+25
-21
src/dictionary.c
src/dictionary.c
+24
-20
src/dictionary.h
src/dictionary.h
+1
-1
未找到文件。
src/dictionary.c
浏览文件 @
beb67e38
...
...
@@ -35,7 +35,7 @@
/* Doubles the allocated size associated to a pointer */
/* 'size' is the current allocated size. */
static
void
*
mem_double
(
void
*
ptr
,
in
t
size
)
static
void
*
mem_double
(
void
*
ptr
,
size_
t
size
)
{
void
*
newptr
;
...
...
@@ -61,11 +61,14 @@ static void * mem_double(void * ptr, int size)
static
char
*
xstrdup
(
const
char
*
s
)
{
char
*
t
;
size_t
len
;
if
(
!
s
)
return
NULL
;
t
=
(
char
*
)
malloc
(
strlen
(
s
)
+
1
)
;
len
=
strlen
(
s
)
+
1
;
t
=
malloc
(
len
)
;
if
(
t
)
{
strcpy
(
t
,
s
)
;
memcpy
(
t
,
s
,
len
)
;
}
return
t
;
}
...
...
@@ -87,9 +90,9 @@ static char * xstrdup(const char * s)
/*--------------------------------------------------------------------------*/
unsigned
dictionary_hash
(
const
char
*
key
)
{
int
len
;
size_t
len
;
unsigned
hash
;
int
i
;
size_t
i
;
len
=
strlen
(
key
);
for
(
hash
=
0
,
i
=
0
;
i
<
len
;
i
++
)
{
...
...
@@ -114,20 +117,21 @@ unsigned dictionary_hash(const char * key)
dictionary, give size=0.
*/
/*--------------------------------------------------------------------------*/
dictionary
*
dictionary_new
(
in
t
size
)
dictionary
*
dictionary_new
(
size_
t
size
)
{
dictionary
*
d
;
/* If no size was specified, allocate space for DICTMINSZ */
if
(
size
<
DICTMINSZ
)
size
=
DICTMINSZ
;
if
(
!
(
d
=
(
dictionary
*
)
calloc
(
1
,
sizeof
(
dictionary
))))
{
return
NULL
;
d
=
calloc
(
1
,
sizeof
*
d
)
;
if
(
d
)
{
d
->
size
=
size
;
d
->
val
=
calloc
(
size
,
sizeof
*
d
->
val
);
d
->
key
=
calloc
(
size
,
sizeof
*
d
->
key
);
d
->
hash
=
calloc
(
size
,
sizeof
*
d
->
hash
);
}
d
->
size
=
size
;
d
->
val
=
(
char
**
)
calloc
(
size
,
sizeof
(
char
*
));
d
->
key
=
(
char
**
)
calloc
(
size
,
sizeof
(
char
*
));
d
->
hash
=
(
unsigned
int
*
)
calloc
(
size
,
sizeof
(
unsigned
));
return
d
;
}
...
...
@@ -142,7 +146,7 @@ dictionary * dictionary_new(int size)
/*--------------------------------------------------------------------------*/
void
dictionary_del
(
dictionary
*
d
)
{
int
i
;
size_t
i
;
if
(
d
==
NULL
)
return
;
for
(
i
=
0
;
i
<
d
->
size
;
i
++
)
{
...
...
@@ -175,7 +179,7 @@ void dictionary_del(dictionary * d)
char
*
dictionary_get
(
dictionary
*
d
,
const
char
*
key
,
char
*
def
)
{
unsigned
hash
;
int
i
;
size_t
i
;
hash
=
dictionary_hash
(
key
);
for
(
i
=
0
;
i
<
d
->
size
;
i
++
)
{
...
...
@@ -220,7 +224,7 @@ char * dictionary_get(dictionary * d, const char * key, char * def)
/*--------------------------------------------------------------------------*/
int
dictionary_set
(
dictionary
*
d
,
const
char
*
key
,
const
char
*
val
)
{
int
i
;
size_t
i
;
unsigned
hash
;
if
(
d
==
NULL
||
key
==
NULL
)
return
-
1
;
...
...
@@ -249,9 +253,9 @@ int dictionary_set(dictionary * d, const char * key, const char * val)
if
(
d
->
n
==
d
->
size
)
{
/* Reached maximum size: reallocate dictionary */
d
->
val
=
(
char
**
)
mem_double
(
d
->
val
,
d
->
size
*
sizeof
(
char
*
)
)
;
d
->
key
=
(
char
**
)
mem_double
(
d
->
key
,
d
->
size
*
sizeof
(
char
*
)
)
;
d
->
hash
=
(
unsigned
int
*
)
mem_double
(
d
->
hash
,
d
->
size
*
sizeof
(
unsigned
)
)
;
d
->
val
=
mem_double
(
d
->
val
,
d
->
size
*
sizeof
*
d
->
val
)
;
d
->
key
=
mem_double
(
d
->
key
,
d
->
size
*
sizeof
*
d
->
key
)
;
d
->
hash
=
mem_double
(
d
->
hash
,
d
->
size
*
sizeof
*
d
->
hash
)
;
if
((
d
->
val
==
NULL
)
||
(
d
->
key
==
NULL
)
||
(
d
->
hash
==
NULL
))
{
/* Cannot grow dictionary */
return
-
1
;
...
...
@@ -288,7 +292,7 @@ int dictionary_set(dictionary * d, const char * key, const char * val)
void
dictionary_unset
(
dictionary
*
d
,
const
char
*
key
)
{
unsigned
hash
;
int
i
;
size_t
i
;
if
(
key
==
NULL
)
{
return
;
...
...
@@ -336,7 +340,7 @@ void dictionary_unset(dictionary * d, const char * key)
/*--------------------------------------------------------------------------*/
void
dictionary_dump
(
dictionary
*
d
,
FILE
*
out
)
{
int
i
;
size_t
i
;
if
(
d
==
NULL
||
out
==
NULL
)
return
;
if
(
d
->
n
<
1
)
{
...
...
src/dictionary.h
浏览文件 @
beb67e38
...
...
@@ -80,7 +80,7 @@ unsigned dictionary_hash(const char * key);
dictionary, give size=0.
*/
/*--------------------------------------------------------------------------*/
dictionary
*
dictionary_new
(
in
t
size
);
dictionary
*
dictionary_new
(
size_
t
size
);
/*-------------------------------------------------------------------------*/
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录