something weird with strerror_r

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 29 06:52:26 PST 2015


On Thursday, 29 January 2015 at 14:40:32 UTC, CodeSun wrote:
> 	writeln(cast(string)buf);

Casting to string is often a mistake, here it might be the 
problem because you didn't check for the zero terminator, so the 
writeln prints all the garbage at the end of the buffer too.

I'd try something like

char[128] buf = 0; // initialize it all to zeroes

// fill it here with the function

printf("%s\n", buf.ptr); // display with printf which respects 0

and see what happens, if that works, the problem is just 
converting from C string back to D string, which you can do with 
to!string(buf.ptr) or another slicing method which is more 
efficient if you search for the zero yourself.


More information about the Digitalmars-d mailing list