1、access函数:检查文件是否存在
2、sleep函数 睡眠多久
3、xmlDocPtr xml文件解析相关
4、xmlParseFile 加载xml文件内容
示例:
xmlDocPtr xml_conf_doc = (xmlDocPtr)NULL;
xml_conf_doc = xmlParseFile (CONF_XML_FILE);
if (NULL == xml_conf_doc)
{
NETCARD_ERRLOG("Parse xml %s failed, maybe hms start firstly\n", CONF_XML_FILE);
return;
}
<pre name="code" class="plain">__FUNCTION__表示函数名,
__LINE__表示在第几行
__FILE__ 包含前程序文件名字符串
__LINE__ 表示前行号整数
__DATE__ 包含前期字符串
__STDC__ 编译器遵循ANSI C标准非零值
__TIME__ 包含前间字符串
errno:错误代码
INET_ADDRSTRLEN
INET6_ADDRSTRLEN
int read_xml_file (const xmlDoc * doc_ptr, const char *xpath, char *buf)
{
int ret_int_num = HMS_FAIL;
xmlChar *content = (xmlChar *)NULL;
xmlXPathContextPtr xpathCtx = (xmlXPathContextPtr)NULL;
xmlXPathObjectPtr xpathObj = (xmlXPathObjectPtr)NULL;
if(NULL == xpath || NULL == buf || NULL == doc_ptr)
{
TOOLSPRINT("parameter error\n");
goto cleanup;
}
/* Create point the xml_doc and malloc memory space */
xpathCtx = xmlXPathNewContext ((xmlDocPtr)doc_ptr);
if (NULL == xpathCtx)
{
TOOLSPRINT("Error: unable to create new XPath context\n");
goto cleanup;
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEval ((xmlChar *)xpath, xpathCtx);
if ((NULL == xpathObj) || (NULL == xpathObj->nodesetval))
{
goto cleanup;
}
/* dispose the node list */
if (!xpathObj->nodesetval->nodeNr)
{
/*HMS_RPRINT(HMS_LOG_DEBUG, "Error: Node not found!\n");*/
goto cleanup;
}
/* dispose the nodeTab[0]==NULL mode */
if (NULL == xpathObj->nodesetval->nodeTab[0])
{
TOOLSPRINT("Error: Node content is NULL!\n");
goto cleanup;
}
content = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
if (NULL == content)
{
goto cleanup;
}
if (MAX_NODE_VALUE_SIZE <= strlen ((char *)content))
{
TOOLSPRINT("The node's content is too large\n");
goto cleanup;
}
if (0 == strlen ((char *)content))
{
TOOLSPRINT("The node's content inexistence\n");
goto cleanup;
}
snprintf (buf, MAX_NODE_VALUE_SIZE, "%s", (char *)content);
ret_int_num = HMS_SUCCESS;
cleanup:
if (NULL != content)
{
xmlFree (content);
}
if (NULL != xpathObj)
{
xmlXPathFreeObject (xpathObj);
}
if (NULL != xpathCtx)
{
xmlXPathFreeContext (xpathCtx);
}
return (ret_int_num);
}