In my dreams yes, but you can't write to c_str mem zone... That's why we
need to reimplement core::string

On 01/03/2013 19:56, joker-eph wrote:
> In pythran/pythonic++/core/file.h:
> 
>> +
>> +				core::string read(int size = -1) {
>> +					if(not is_open) throw ValueError("I/O operation on closed file");
>> +					if (mode.find_first_of("r+") == std::string::npos)
>> +						throw IOError("File not open for reading");
>> +					if (size == 0 or (feof(**data) && mode.find_first_of("ra") == std::string::npos) ) return core::string();
>> +					int curr_pos = tell();
>> +					seek(0, SEEK_END);
>> +					size = size < 0 ? tell() - curr_pos : size;
>> +					seek(curr_pos);
>> +					char *content = new char[size+1];
>> +					// Putting a '\0' after relevant info even if size is > number of bits in file.
>> +					content[fread(content, sizeof(char), size, **data)] = '\0';
>> +					// This part needs a new implementation of core::string(char*) to avoid unnecessary copy.
>> +					core::string res(content);
>> +					delete[] content;
> 
> What about :
> core::string content;
> content.reserve(size+1);
> content[fread(content.c_str(), sizeof(char), size, **data)]='\0';
> 
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/serge-sans-paille/pythran/pull/53/files#r3208956>.
>