prefer memcpy() to strncpy()

Replace `strncpy()`, which isn't a safer version of `strcpy()`, with `memcpy()` calls.
Also get rid of duplicate `strlen()` calls and properly null-terminate the string returned by `dirname()` in `apilist.c`!