使用glib库函数,能读出文件内容,但用g_key_file_load_from_data填结构体出错

jiahehao 2009-02-26 02:23:04
我主要参考的是网上的这篇文章:http://www.diybl.com/course/6_system/linux/Linuxjs/2008625/128344.html

使用了把key对应的data写进去的 write_item 和 读key对应的data simple_get_conf_item两个方法。读出文件没有问题,但是在写入文件用write_item 方法时,用它的g_key_file_load_from_data 方法总是报错,这个方法是把内存中的内容填到一个结构体中去。
我在前面一句的printf("%s():data = %s\n", __FUNCTION__, file_data)中,看到要改写的内容都打印出来了,但这句却执行错误。不明白原因,请大家赐教。

以下是主要功能代码:
************

//get the old DB IP from conf/ss.conf
old_DB_address=simple_get_conf_item(Z_SS_V4_CONF_DIR,Z_CONFIG_DEF,Z_M_NAME_DBI, "MySqlHost");
g_debug("old database IP is %s\n",old_DB_address.c_str());

//if new DB'ip equal to old,then set myself to master,nor set to slave;
pathconfig = "d:/etc";
if (old_DB_address.compare(new_DB_address) == 0)
{
   //this computer would set to master status;
   new_DB_address = "";
}

//get hostname and
if( (ret = gethostname(hostname,128))==0)
     { 
    sprintf(hostname_relay_bin, "rm -f /var/lib/mysql/%s-relay-bin.*",hostname);
    sprintf(hostname_bin_index, "rm -f /var/lib/mysql/%s-relay-bin.index",hostname);

g_debug("the cmd1 is %s!\n",hostname_relay_bin);
g_debug("the cmd2 is %s! \n",hostname_bin_index);
}

//set the my.conf status;
     ret= write_item(pathconfig,"my.txt", "mysqld", "master-host", (char * )new_DB_address.c_str());
  if(ret==1)
{
  g_debug("write_item error \n");
  return -1;
}
*****************
...全文
474 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
waizqfor 2009-02-26
  • 打赏
  • 举报
回复
先看看!~
  • 打赏
  • 举报
回复
帮顶吧,没用过这种库.

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧