Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Iniparser
提交
3c23bf85
T
Third Party Iniparser
项目概览
OpenHarmony
/
Third Party Iniparser
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
3c23bf85
编写于
5月 16, 2015
作者:
E
Emmanuel Leblond
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
iniparser_getseckeys doesn't return a malloc ptr anymore (see #30)
上级
85023c97
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
51 deletion
+46
-51
src/iniparser.c
src/iniparser.c
+12
-23
src/iniparser.h
src/iniparser.h
+9
-8
test/test_iniparser.c
test/test_iniparser.c
+25
-20
未找到文件。
src/iniparser.c
浏览文件 @
3c23bf85
...
...
@@ -310,36 +310,26 @@ int iniparser_getsecnkeys(const dictionary * d, const char * s)
/*-------------------------------------------------------------------------*/
/**
@brief Get the number of keys in a section of a dictionary.
@param d Dictionary to examine
@param s Section name of dictionary to examine
@return pointer to statically allocated character strings
@param d Dictionary to examine
@param s Section name of dictionary to examine
@param keys Already allocated array to store the keys in
@return The pointer passed as `keys` argument or NULL in case of error
This function queries a dictionary and finds all keys in a given section.
The returned pointer is obtained with malloc(3), and can be freed
with free(3).
The keys argument should be an array of pointers which size has been
determined by calling `iniparser_getsecnkeys` function prior to this one.
Each pointer in the returned char pointer-to-pointer is pointing to
a string allocated in the dictionary; do not free or modify them.
This function returns NULL in case of error.
*/
/*--------------------------------------------------------------------------*/
const
char
**
iniparser_getseckeys
(
const
dictionary
*
d
,
const
char
*
s
)
const
char
**
iniparser_getseckeys
(
const
dictionary
*
d
,
const
char
*
s
,
const
char
**
keys
)
{
int
i
,
j
,
seclen
;
char
keym
[
ASCIILINESZ
+
1
];
const
char
**
keys
;
int
i
,
j
;
char
keym
[
ASCIILINESZ
+
1
];
int
seclen
,
nkeys
;
keys
=
NULL
;
if
(
d
==
NULL
)
return
keys
;
if
(
!
iniparser_find_entry
(
d
,
s
))
return
keys
;
nkeys
=
iniparser_getsecnkeys
(
d
,
s
);
keys
=
(
const
char
**
)
malloc
(
nkeys
*
sizeof
(
char
*
));
if
(
d
==
NULL
||
keys
==
NULL
)
return
NULL
;
if
(
!
iniparser_find_entry
(
d
,
s
))
return
NULL
;
seclen
=
(
int
)
strlen
(
s
);
sprintf
(
keym
,
"%s:"
,
s
);
...
...
@@ -356,7 +346,6 @@ const char ** iniparser_getseckeys(const dictionary * d, const char * s)
}
return
keys
;
}
/*-------------------------------------------------------------------------*/
...
...
src/iniparser.h
浏览文件 @
3c23bf85
...
...
@@ -128,20 +128,21 @@ int iniparser_getsecnkeys(const dictionary * d, const char * s);
/*-------------------------------------------------------------------------*/
/**
@brief Get the number of keys in a section of a dictionary.
@param d Dictionary to examine
@param s Section name of dictionary to examine
@return pointer to statically allocated character strings
@param d Dictionary to examine
@param s Section name of dictionary to examine
@param keys Already allocated array to store the keys in
@return The pointer passed as `keys` argument or NULL in case of error
This function queries a dictionary and finds all keys in a given section.
The returned pointer is obtained with malloc(3), and can be freed
with free(3).
The keys argument should be an array of pointers which size has been
determined by calling `iniparser_getsecnkeys` function prior to this one.
Each pointer in the returned char pointer-to-pointer is pointing to
a string allocated in the dictionary; do not free or modify them.
This function returns NULL in case of error.
*/
/*--------------------------------------------------------------------------*/
const
char
**
iniparser_getseckeys
(
const
dictionary
*
d
,
const
char
*
s
);
const
char
**
iniparser_getseckeys
(
const
dictionary
*
d
,
const
char
*
s
,
const
char
**
keys
);
/*-------------------------------------------------------------------------*/
/**
...
...
test/test_iniparser.c
浏览文件 @
3c23bf85
...
...
@@ -195,28 +195,32 @@ void Test_iniparser_getseckeys(CuTest *tc)
unsigned
i
;
char
key_name
[
64
];
dictionary
*
dic
;
const
char
**
sections
;
int
nkeys
;
const
char
*
keys
[
10
];
/* At most 10 elements per section */
/* NULL test */
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
NULL
,
NULL
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
NULL
,
"dummy"
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
NULL
,
NULL
,
NULL
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
NULL
,
"dummy"
,
NULL
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
NULL
,
"dummy"
,
keys
));
/* Empty dictionary */
dic
=
dictionary_new
(
10
);
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
NULL
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"dummy"
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
NULL
,
keys
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"dummy"
,
keys
));
dictionary_del
(
dic
);
/* Generic dictionary */
dic
=
generate_dictionary
(
100
,
10
);
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
NULL
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"dummy"
));
sections
=
iniparser_getseckeys
(
dic
,
"sec42"
);
CuAssertPtrNotNull
(
tc
,
sections
);
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
NULL
,
keys
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"dummy"
,
keys
));
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"sec0"
,
NULL
));
nkeys
=
iniparser_getsecnkeys
(
dic
,
"sec42"
);
CuAssertIntEquals
(
tc
,
nkeys
,
10
);
CuAssertPtrEquals
(
tc
,
keys
,
iniparser_getseckeys
(
dic
,
"sec42"
,
keys
));
for
(
i
=
0
;
i
<
10
;
++
i
)
{
sprintf
(
key_name
,
"sec42:key%d"
,
i
);
CuAssertStrEquals
(
tc
,
key_name
,
section
s
[
i
]);
CuAssertStrEquals
(
tc
,
key_name
,
key
s
[
i
]);
}
free
(
sections
);
/* Remove some keys to make the dictionary more real */
dictionary_unset
(
dic
,
"sec42"
);
...
...
@@ -225,21 +229,22 @@ void Test_iniparser_getseckeys(CuTest *tc)
dictionary_unset
(
dic
,
"sec0:key1"
);
dictionary_unset
(
dic
,
"sec0:key2"
);
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"sec42"
));
sections
=
iniparser_getseckeys
(
dic
,
"sec99"
);
CuAssertPtrNotNull
(
tc
,
sections
);
CuAssertPtrEquals
(
tc
,
NULL
,
iniparser_getseckeys
(
dic
,
"sec42"
,
keys
));
nkeys
=
iniparser_getsecnkeys
(
dic
,
"sec99"
);
CuAssertIntEquals
(
tc
,
nkeys
,
9
);
CuAssertPtrEquals
(
tc
,
keys
,
iniparser_getseckeys
(
dic
,
"sec99"
,
keys
));
for
(
i
=
0
;
i
<
9
;
++
i
)
{
sprintf
(
key_name
,
"sec99:key%d"
,
i
);
CuAssertStrEquals
(
tc
,
key_name
,
section
s
[
i
]);
CuAssertStrEquals
(
tc
,
key_name
,
key
s
[
i
]);
}
free
(
sections
);
sections
=
iniparser_getseckeys
(
dic
,
"sec0"
);
CuAssertPtrNotNull
(
tc
,
sections
);
nkeys
=
iniparser_getsecnkeys
(
dic
,
"sec0"
);
CuAssertIntEquals
(
tc
,
nkeys
,
7
);
CuAssertPtrEquals
(
tc
,
keys
,
iniparser_getseckeys
(
dic
,
"sec0"
,
keys
));
for
(
i
=
0
;
i
<
7
;
++
i
)
{
sprintf
(
key_name
,
"sec0:key%d"
,
i
+
3
);
CuAssertStrEquals
(
tc
,
key_name
,
section
s
[
i
]);
CuAssertStrEquals
(
tc
,
key_name
,
key
s
[
i
]);
}
free
(
sections
);
dictionary_del
(
dic
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录