Avoid shadowing the global filename. Reorg mangle_filename to be more
precise in the length accounting and use memcpy instead of
strcpy/strcat.

Differential Revision: http://llvm-reviews.chandlerc.com/D2547