Fix copy & paste

Some of the code was mis-handling wide character filenames.

A direct copy & paste should be using the 8-bit form of the filename,
but that's a deeper fix.

Also, changed some types to use explicit integer width specifiers.