cf_void WritePid()
    {
        char p [MAX_SIZE];
        GetPathByPathNameExt(_filePathName.c_str(), _filePathName.size() , p);
        if(0==IsFileExist(p))
        {
            if(-1==mkdir(p, S_IRWXU | S_IRWXG | S_IROTH))
            {
                _THROW(SyscallExecuteError, "Failed to execute mkdir !");
            }
        }

        _fd =cf_open(_filePathName.c_str(),O_RDWR|O_CREAT|O_TRUNC,
                     S_IRWXU | S_IRWXG | S_IROTH);
        if(-1==_fd)
        {
            _THROW(SyscallExecuteError, "Failed to execute cf_open !");
        }
        char buf[8] = {0};
        int n =snprintf(buf,sizeof(buf),"%u",unsigned(getpid()));
        ssize_t nw =cf_write(_fd,buf,n);
        if(nw!=n)
        {
            _THROW_FMT(ValueError, "nw{%d}!=n{%d} !",int(nw),int(n));
        }
    }
示例#2
0
文件: keyfile.c 项目: iven/cugbfreer
void cf_key_file_save (void) {
    gchar *config_file_path;
    gchar *key_file_data;
    config_file_path = g_build_filename (g_get_user_config_dir (), CF_CONFIG_FILE_NAME, NULL);
    key_file_data = g_key_file_to_data (cf_key_file, NULL, NULL);
    cf_write (config_file_path, key_file_data);
    g_free (key_file_data);
    g_key_file_free (cf_key_file);
}