llvm.org GIT mirror llvm / 04cb564
Replace the use of strncpy() and sprintf() with std::string and LLVM streams. Patch by Martinez, Javier E. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164822 91177308-0d34-0410-b5e6-96231b3b80d8 Dmitri Gribenko 6 years ago
1 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1212
1313 #include "llvm/Support/Errno.h"
1414 #include "llvm/Config/config.h" // Get autoconf configuration settings
15 #include "llvm/Support/raw_ostream.h"
1516
1617 #if HAVE_STRING_H
1718 #include
3839 const int MaxErrStrLen = 2000;
3940 char buffer[MaxErrStrLen];
4041 buffer[0] = '\0';
41 char* str = buffer;
42 std::string str;
4243 #ifdef HAVE_STRERROR_R
4344 // strerror_r is thread-safe.
4445 if (errnum)
4849 str = strerror_r(errnum,buffer,MaxErrStrLen-1);
4950 # else
5051 strerror_r(errnum,buffer,MaxErrStrLen-1);
52 str = buffer;
5153 # endif
5254 #elif HAVE_DECL_STRERROR_S // "Windows Secure API"
5355 if (errnum)
5759 // the buffer as fast as possible to minimize impact
5860 // of collision of strerror in multiple threads.
5961 if (errnum)
60 strncpy(buffer,strerror(errnum),MaxErrStrLen-1);
61 buffer[MaxErrStrLen-1] = '\0';
62 str = strerror(errnum);
6263 #else
6364 // Strange that this system doesn't even have strerror
6465 // but, oh well, just use a generic message
65 sprintf(buffer, "Error #%d", errnum);
66 raw_string_ostream stream(str);
67 stream << "Error #" << errnum;
68 stream.flush();
6669 #endif
6770 return str;
6871 }