Avoid declaring unused variables

Move the variable declarations within the ifdef instead.
Check a string length before doing a strncpy
Merge pull request #310 from mstorsjo/remove-unused-variables

Avoid declaring unused variables