| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Copyright 2013 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-20 04:11:52 +01:00
										 |  |  | #include <cstddef>
 | 
					
						
							|  |  |  | #include <cstring>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-18 23:17:41 -05:00
										 |  |  | #include "Common/CommonFuncs.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 22:52:53 -05:00
										 |  |  | // Neither Android nor OS X support TLS
 | 
					
						
							|  |  |  | #if  defined(__APPLE__) || (ANDROID && __clang__)
 | 
					
						
							| 
									
										
										
										
											2011-03-16 22:58:24 +00:00
										 |  |  | #define __thread
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | // Generic function to get last error message.
 | 
					
						
							|  |  |  | // Call directly after the command or use the error num.
 | 
					
						
							|  |  |  | // This function might change the error code.
 | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | const char* GetLastErrorMsg() | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 	static const size_t buff_size = 255; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | #ifdef _WIN32
 | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 	static __declspec(thread) char err_str[buff_size] = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 	FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 		err_str, buff_size, nullptr); | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 	static __thread char err_str[buff_size] = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | 	// Thread safe (XSI-compliant)
 | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 	strerror_r(errno, err_str, buff_size); | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-16 21:08:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return err_str; | 
					
						
							| 
									
										
										
										
											2009-03-07 08:35:01 +00:00
										 |  |  | } |