hls: fix keyvalues with \0 inside

It could happen that some keyfiles have \0 in them. To fix I've created another function that uses memcpy instead of strdup.
Also, I've switched all sprintf to snprintf.