On Mon, Jun 06, 2011 at 04:10:09PM +0100, Dave Challis wrote:
> I've got an erlang program which uses binary strings (e.g.
> <<"abc">>), and a c port with some functions which operate on char
> Is it safe to pass this binary string directly to c (using
> ei_decode_binary) for use in char arrays?
> Or should I always use binary_to_list(<<"abc">>) before passing it
> to c, then decode using ei_decode_string?
> My main worry is whether binary strings in erlang could contain the
> null character somewhere (e.g. passing <<"abc\0def">> to c port and
> decoding as a binary results in c seeing the string "abc").
Yes, it's safe for NULLs. The external term format puts the length of
the binary in the header: