Note, for reference, that the strncpy() above is Wrong On So Many Levels, though !  It shouldn't have -1 on its buffer size; and it should be strlcpy(), instead, to avoid wantonly filling the tail of the array (when there *is* enough space to terminate) with '\0' bytes.  However, I suppose your changes shall imply significant reworking of this code anyway ...