Fix cpack crash sometimes while packing
See the reference: https://msdn.microsoft.com/en-us/library/x99tb11d.aspx
You can copy the string returned by setlocale to restore that part of the program's locale information. Global or thread local storage is used for the string returned by setlocale. Later calls to setlocale overwrite the string, which invalidates string pointers returned by earlier calls.