开发者

How to prevent iostreams::mapped_file_sink from creating executable txt files

开发者 https://www.devze.com 2023-03-09 07:37 出处:网络
EDIT: code sample is broken, it is missing .is_open(), please DON\'T use it. I have a rather strange question. I use boost iostreams and they work awesome, but the problem is that files that program

EDIT: code sample is broken, it is missing .is_open(), please DON'T use it. I have a rather strange question. I use boost iostreams and they work awesome, but the problem is that files that program creates are executable txt files(I'm on ubuntu,msg is :""lol2.txt" is an executable text file."). So is there any way to make it a regular nonexecutable file. I would like to change the code so that it doesnt create executable, files I know I can change the file after it is created from terminal or Nautilus. btw this is the code that I'm using:

void write_file(const std::string& name,string data)
{
    iostreams::mapped_file_params params;
  开发者_运维百科  params.new_file_size=data.size();
    params.path=name;
    iostreams::mapped_file_sink file(params);
    memcpy(file.data(),&data[0],data.size());
}


You can change the file creation mask of your process to create non-executable files by default:

umask(getumask() & ~(S_IXUSR | S_IXGRP | S_IXOTH));
0

精彩评论

暂无评论...
验证码 换一张
取 消