Author: chaoren Date: Fri May 29 14:34:57 2015 New Revision: 238599 URL: http://llvm.org/viewvc/llvm-project?rev=238599&view=rev Log: Implement snprintf for MSVC with correct return value.
Reviewers: zturner Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D10048 Modified: lldb/trunk/include/lldb/Host/windows/win32.h lldb/trunk/source/Host/windows/Windows.cpp Modified: lldb/trunk/include/lldb/Host/windows/win32.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/win32.h?rev=238599&r1=238598&r2=238599&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/windows/win32.h (original) +++ lldb/trunk/include/lldb/Host/windows/win32.h Fri May 29 14:34:57 2015 @@ -52,7 +52,7 @@ typedef unsigned short mode_t; #ifdef LLDB_DISABLE_PYTHON typedef uint32_t pid_t; -#endif +#endif // LLDB_DISABLE_PYTHON int usleep(uint32_t useconds); @@ -63,6 +63,7 @@ char *dirname(char *path); int strcasecmp(const char* s1, const char* s2); int strncasecmp(const char* s1, const char* s2, size_t n); +int snprintf(char *buffer, size_t count, const char *format, ...); #define STDIN_FILENO 0 #define STDOUT_FILENO 1 @@ -73,8 +74,7 @@ int strncasecmp(const char* s1, const ch #define S_IFDIR _S_IFDIR #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define snprintf _snprintf -#endif +#endif // _MSC_VER // timespec struct timespec Modified: lldb/trunk/source/Host/windows/Windows.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Windows.cpp?rev=238599&r1=238598&r2=238599&view=diff ============================================================================== --- lldb/trunk/source/Host/windows/Windows.cpp (original) +++ lldb/trunk/source/Host/windows/Windows.cpp Fri May 29 14:34:57 2015 @@ -198,8 +198,33 @@ int strncasecmp(const char* s1, const ch int usleep(uint32_t useconds) { - Sleep(useconds / 1000); - return 0; + Sleep(useconds / 1000); + return 0; +} + +int snprintf(char *buffer, size_t count, const char *format, ...) +{ + int old_errno = errno; + va_list argptr; + va_start(argptr, format); + int r = vsnprintf(buffer, count, format, argptr); + int new_errno = errno; + buffer[count-1] = '\0'; + if (r == -1 || r == count) + { + FILE *nul = fopen("nul", "w"); + int bytes_written = vfprintf(nul, format, argptr); + fclose(nul); + if (bytes_written < count) + errno = new_errno; + else + { + errno = old_errno; + r = bytes_written; + } + } + va_end(argptr); + return r; } #endif // _MSC_VER _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits