extern int vasprintf(char **ptr, const char *f, va_list arg);
/*
* Declare vswprintf on platforms where it's not known to exist. We know
- * it's available on glibc >= 2.2, FreeBSD >= 5.0, and all versions of
+ * it's available on glibc >= 2.2, FreeBSD >= 5.0, and all versions of
* Solaris.
* (Re: Solaris, vswprintf has been present since Solaris 8, and we only
* support Solaris 9 and above, since that was the first release available
*
* Str_Vsnprintf --
*
- * Compatibility wrapper b/w different libc versions
+ * Compatibility wrapper b/w different libc versions
*
* Results:
*
- * int - number of bytes stored in 'str' (not including NUL
- * terminate character), -1 on overflow (insufficient space for
- * NUL terminate is considered overflow)
+ * int - number of bytes stored in 'str' (not including NUL
+ * terminate character), -1 on overflow (insufficient space for
+ * NUL terminate is considered overflow)
*
- * NB: on overflow the buffer WILL be NUL terminated at the last
- * UTF-8 code point boundary within the buffer's bounds.
+ * NB: on overflow the buffer WILL be NUL terminated at the last
+ * UTF-8 code point boundary within the buffer's bounds.
*
* WARNING: See warning at the top of this file.
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
const char *fmt, // IN:
...) // IN:
{
- uint32 *stack = (uint32*) &buf;
va_list args;
int retval;
ASSERT(buf);
ASSERT(fmt);
-
+
va_start(args, fmt);
retval = bsd_vsnprintf_c_locale(&buf, maxSize, fmt, args);
va_end(args);
}
if (retval >= maxSize) {
- Panic("%s:%d Buffer too small 0x%x\n", __FILE__, __LINE__, stack[-1]);
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
}
return retval;
const char *fmt, // IN
...) // IN
{
- uint32 *stack = (uint32*) &buf;
va_list args;
int i;
-
+
va_start(args, fmt);
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\n", __FILE__, __LINE__);
}
return i;
}
*
* Str_Snprintf --
*
- * Compatibility wrapper b/w different libc versions
+ * Compatibility wrapper b/w different libc versions
*
* Results:
*
- * int - number of bytes stored in 'str' (not including NUL
- * terminate character), -1 on overflow (insufficient space for
- * NUL terminate is considered overflow)
+ * int - number of bytes stored in 'str' (not including NUL
+ * terminate character), -1 on overflow (insufficient space for
+ * NUL terminate is considered overflow)
*
- * NB: on overflow the buffer WILL be NUL terminated
+ * NB: on overflow the buffer WILL be NUL terminated
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
-int
+int
Str_Snprintf(char *str, // OUT
size_t size, // IN
const char *format, // IN
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]);
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
ASSERT_BUG(5686, FALSE);
}
return memcpy(buf, src, len + 1);
* Calculate length of the string.
*
* Results:
- * Length of s not including the terminating '\0' character.
+ * Length of s not including the terminating '\0' character.
* If there is no '\0' for first maxLen bytes, then it
* returns maxLen.
*
*/
size_t
-Str_Strlen(const char *s, // IN
- size_t maxLen) // IN
+Str_Strlen(const char *s, // IN:
+ size_t maxLen) // IN:
{
const char *end;
if ((end = memchr(s, '\0', maxLen)) == NULL) {
return maxLen;
- }
+ }
return end - s;
}
*
* Str_Strnstr --
*
- * Find a substring within a string of length at most n. 'sub' must be
+ * Find a substring within a string of length at most n. 'sub' must be
* NUL-terminated. 'n' is interpreted as an unsigned int.
*
* Results:
- * A pointer to the beginning of the substring, or NULL if not found.
+ * A pointer to the beginning of the substring, or NULL if not found.
*
* Side Effects:
* None
*/
char *
-Str_Strnstr(const char *src, // IN
- const char *sub, // IN
- size_t n) // IN
-
+Str_Strnstr(const char *src, // IN:
+ const char *sub, // IN:
+ size_t n) // IN:
{
size_t subLen;
const char *end;
return NULL;
}
for (;
- (src = memchr(src, sub[0], end - src)) != NULL &&
- memcmp(src, sub, subLen) != 0;
- src++) {
+ (src = memchr(src, sub[0], end - src)) != NULL &&
+ memcmp(src, sub, subLen) != 0;
+ src++) {
}
return (char *) src;
}
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\n", __FILE__, __LINE__);
}
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;
+ size_t bufLen;
ASSERT(buf != NULL);
ASSERT(src != NULL);
- stack = (uint32 *)&buf;
- bufLen = strlen(buf);
-
/*
* Check bufLen + n first so we can avoid the second call to strlen
* if possible.
* happen by adding the == case to the Panic test.
*/
+ 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\n", __FILE__,__LINE__);
}
/*
{
va_list arguments;
char *result;
-
+
va_start(arguments, format);
result = Str_SafeVasprintf(length, format, arguments);
va_end(arguments);
const wchar_t *fmt, // IN
...) // IN
{
- uint32 *stack = (uint32*) &buf;
va_list args;
int i;
-
+
va_start(args,fmt);
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\n", __FILE__, __LINE__);
}
return i;
}
*
* Str_Vsnwprintf --
*
- * Compatibility wrapper b/w different libc versions
+ * Compatibility wrapper b/w different libc versions
*
* Results:
*
- * int - number of wchar_ts stored in 'str' (not including NUL
- * terminate character), -1 on overflow (insufficient space for
- * NUL terminate is considered overflow)
+ * int - number of wchar_ts stored in 'str' (not including NUL
+ * terminate character), -1 on overflow (insufficient space for
+ * NUL terminate is considered overflow)
*
- * NB: on overflow the buffer WILL be NUL terminated
+ * NB: on overflow the buffer WILL be NUL terminated
*
* WARNING: See warning at the top of this file.
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
*
* Str_Snwprintf --
*
- * Compatibility wrapper b/w different libc versions
+ * Compatibility wrapper b/w different libc versions
*
* Results:
*
- * int - number of wchar_ts stored in 'str' (not including NUL
- * terminate character), -1 on overflow (insufficient space for
- * NUL terminate is considered overflow)
+ * int - number of wchar_ts stored in 'str' (not including NUL
+ * terminate character), -1 on overflow (insufficient space for
+ * NUL terminate is considered overflow)
*
- * NB: on overflow the buffer WILL be NUL terminated
+ * NB: on overflow the buffer WILL be NUL terminated
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
-int
+int
Str_Snwprintf(wchar_t *str, // OUT
size_t size, // IN: Size of str, in wide-characters.
const wchar_t *format, // IN
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);
+ if (len >= maxSize) {
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
+ ASSERT_BUG(5686, FALSE);
}
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\n", __FILE__, __LINE__);
}
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\n", __FILE__,__LINE__);
}
/*
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\n", __FILE__, __LINE__);
}
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\n", __FILE__, __LINE__);
}
memcpy(buf + bufLen, src, srcLen + 1);
{
va_list arguments;
wchar_t *result;
-
+
va_start(arguments, format);
result = Str_Vaswprintf(length, format, arguments);
va_end(arguments);
{
va_list arguments;
wchar_t *result;
-
+
va_start(arguments, format);
result = Str_SafeVaswprintf(length, format, arguments);
va_end(arguments);
char buf1[1024], buf2[1024];
int count;
va_list args;
-
+
va_start(args, fmt);
count = Str_Vsnprintf(buf1, sizeof buf1, fmt, args);
va_end(args);
wchar_t buf1[1024], buf2[1024];
int count;
va_list args;
-
+
va_start(args, fmt);
count = Str_Vsnwprintf(buf1, sizeof buf1, fmt, args);
va_end(args);