So, it looks like in Linux I can't use the constructor
string (const char* s, size_t n)
(as Kevin suggested above).
This leaves me with two options. If I want to truncate the read line (remove the trailing newline), I can either truncate the C-string prior to using it to create the C++ string:
if !keep_newlines {
line![readCount - 1] = 0
}
let cpps = std.string(line)
free(line)
return cpps
or I can truncate the C++ string after it was created:
var cpps = std.string(line)
free(line)
if !keep_newlines {
cpps.pop_back()
}
return cpps
Both options work and the performance is pretty much the same. @PaulMcKenzie, @Kevin, @Remy Lebeau - Thanks for your suggestions.