C / C ++ lines end with NULL, which means that the first character \0 marks the end of the line.
When a function returns a pointer to such a string, the calling object (SWIG in this case) does not know if there is more data after the first \0 , so you only get the first part.
So, first you need to change the C function to return not only the string, but also its length. Since there can only be one return value, we will use pointer arguments.
void fun(char** s, int *sz) { *s = "abc\0de"; *sz = 6; }
SWIG documents suggest using cstring.i library to port such functions. In particular, the last macro does exactly what you need.
%cstring_output_allocate_size(parm, szparm, release)
Read the docs to find out how to use it.
source share