Const correctness.
Fix a possible buffer overflow: mbstowcs takes character, not byte, count.
Replace hard-wired sizes with sizeof().