Don't forget to NUL terminate if the last line did not have delim.
From: Hubert Garavel