#include "bsd_output.h"
#endif
#include "codeset.h"
+#if defined(GLIBC_VERSION_23)
+#define MAX_ERRSTR_SIZE 128
+#endif
#if defined _WIN32 && !defined HAS_BSD_PRINTF
#define vsnprintf _vsnprintf
const char *fmt, // IN
...) // IN
{
- uint32 *stack = (uint32*) &buf;
va_list args;
int i;
i = Str_Vsnprintf(buf, maxSize, fmt, args);
va_end(args);
if (i < 0) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
return i;
}
const char *src, // IN
size_t maxSize) // IN
{
- uint32 *stack = (uint32 *)&buf;
size_t len;
ASSERT(buf != NULL);
len = strlen(src);
if (len >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
- ASSERT_BUG(5686, FALSE);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
+ ASSERT_BUG(5686, FALSE); // Presumably in case Panic is stubbed
}
return memcpy(buf, src, len + 1);
}
const char *src, // IN
size_t maxSize) // IN
{
- uint32 *stack = (uint32 *)&buf;
size_t bufLen;
size_t srcLen;
/* The first comparison checks for numeric overflow */
if (bufLen + srcLen < srcLen || bufLen + srcLen >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
memcpy(buf + bufLen, src, srcLen + 1);
const char *src, // IN: String to append
size_t n) // IN: Max chars of src to append
{
- uint32 *stack;
size_t bufLen;
ASSERT(buf != NULL);
ASSERT(src != NULL);
- stack = (uint32 *)&buf;
bufLen = strlen(buf);
/*
if (bufLen + n >= bufSize &&
bufLen + strlen(src) >= bufSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__,__LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__,__LINE__,
+ GetReturnAddress());
}
/*
}
+#if defined(GLIBC_VERSION_23)
+/*
+ *----------------------------------------------------------------------
+ *
+ * Str_Strerror --
+ *
+ * User level wrapper for strerror that is thread safe.
+ *
+ * Results:
+ * Same as strerror.
+ *
+ * Side effects:
+ * Allocates per-thread strerror string.
+ *
+ *----------------------------------------------------------------------
+ */
+
+const char *
+Str_Strerror(int errnum) // IN: errno value
+{
+ static __thread char strerrorString[MAX_ERRSTR_SIZE];
+ char *ret;
+
+ ret = strerror_r(errnum, strerrorString, MAX_ERRSTR_SIZE);
+
+ if (!ret) {
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
+ }
+
+ return ret;
+}
+#endif
+
+
/*
*-----------------------------------------------------------------------------
*
const wchar_t *fmt, // IN
...) // IN
{
- uint32 *stack = (uint32*) &buf;
va_list args;
int i;
i = Str_Vsnwprintf(buf, maxSize, fmt, args);
va_end(args);
if (i < 0) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
return i;
}
const wchar_t *src, // IN
size_t maxSize) // IN: Size of buf, in wide-characters.
{
- uint32 *stack = (uint32 *)&buf;
size_t len;
len = wcslen(src);
if (len >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
- ASSERT_BUG(5686, FALSE);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
+ ASSERT_BUG(5686, FALSE); // Presumably in case Panic is stubbed
}
return memcpy(buf, src, (len + 1)*sizeof(wchar_t));
}
const wchar_t *src, // IN
size_t maxSize) // IN: Size of buf, in wide-characters.
{
- uint32 *stack = (uint32 *)&buf;
size_t bufLen;
size_t srcLen;
/* The first comparison checks for numeric overflow */
if (bufLen + srcLen < srcLen || bufLen + srcLen >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
memcpy(buf + bufLen, src, (srcLen + 1)*sizeof(wchar_t));
const wchar_t *src, // IN: String to append
size_t n) // IN: Max chars of src to append
{
- uint32 *stack = (uint32 *)&buf;
size_t bufLen = wcslen(buf);
/*
if (bufLen + n >= bufSize &&
bufLen + wcslen(src) >= bufSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__,__LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__,__LINE__,
+ GetReturnAddress());
}
/*
const char *src, // IN
size_t maxSize) // IN
{
- uint32 *stack = (uint32 *)&buf;
size_t len;
len = strlen((const char *) src);
if (len >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
return memcpy(buf, src, len + 1);
}
const char *src, // IN
size_t maxSize) // IN
{
- uint32 *stack = (uint32 *)&buf;
size_t bufLen;
size_t srcLen;
/* The first comparison checks for numeric overflow */
if (bufLen + srcLen < srcLen || bufLen + srcLen >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small %p\n", __FILE__, __LINE__,
+ GetReturnAddress());
}
memcpy(buf + bufLen, src, srcLen + 1);