如何从ofstream获取文件描述符

时间:2017-10-31 11:17:12

标签: c++ file descriptor fsync

我需要调用fsync()来保护我的数据。你能帮我从ofstream获取文件描述符吗?

string tmpconfig("config.tmp");
ofstream tcfg(tmpconfig.c_str());
if(tcfg)
{
tcfgNV.compactPrint(tcfg);
tcfg.flush();
if(!tcfg.good())
{
    tcfg.close();
    ::remove(tmpconfig.c_str());
    cout << "Failed to write the main configuration file: " << topconfig << endl;
    return false;
}
REPORT_INFO("Syncing the file: " << topconfig);
// TODO I need to call fsync() here to secure my data.
//tcfg.pubsync();
tcfg.close();
}

0 个答案:

没有答案