gallium: Don't assume snprintf are always available.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "pipe/p_debug.h"
|
||||
#include "pipe/p_util.h"
|
||||
#include "pipe/p_shader_tokens.h"
|
||||
#include "util/u_string.h"
|
||||
#include "tgsi_dump.h"
|
||||
#include "tgsi_parse.h"
|
||||
#include "tgsi_build.h"
|
||||
@@ -147,7 +148,7 @@ gen_dump_uix(
|
||||
{
|
||||
char str[36];
|
||||
|
||||
sprintf( str, "0x%x", ui );
|
||||
util_snprintf( str, sizeof(str), "0x%x", ui );
|
||||
gen_dump_str( dump, str );
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ gen_dump_uid(
|
||||
{
|
||||
char str[16];
|
||||
|
||||
sprintf( str, "%u", ui );
|
||||
util_snprintf( str, sizeof(str), "%u", ui );
|
||||
gen_dump_str( dump, str );
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ gen_dump_sid(
|
||||
{
|
||||
char str[16];
|
||||
|
||||
sprintf( str, "%d", si );
|
||||
util_snprintf( str, sizeof(str), "%d", si );
|
||||
gen_dump_str( dump, str );
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ gen_dump_flt(
|
||||
{
|
||||
char str[48];
|
||||
|
||||
sprintf( str, "%10.4f", flt );
|
||||
util_snprintf( str, sizeof(str), "%10.4f", flt );
|
||||
gen_dump_str( dump, str );
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "pipe/p_util.h"
|
||||
#include "pipe/p_debug.h"
|
||||
#include "util/u_string.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -60,7 +61,7 @@ void _debug_vprintf(const char *format, va_list ap)
|
||||
/* EngDebugPrint does not handle float point arguments, so we need to use
|
||||
* our own vsnprintf implementation */
|
||||
char buf[512 + 1];
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
util_vsnprintf(buf, sizeof(buf), format, ap);
|
||||
_EngDebugPrint("%s", buf);
|
||||
#else
|
||||
/* TODO: Implement debug print for WINCE */
|
||||
@@ -311,7 +312,7 @@ debug_dump_enum(const struct debug_named_value *names,
|
||||
++names;
|
||||
}
|
||||
|
||||
snprintf(rest, sizeof(rest), "0x%08lx", value);
|
||||
util_snprintf(rest, sizeof(rest), "0x%08lx", value);
|
||||
return rest;
|
||||
}
|
||||
|
||||
@@ -344,7 +345,7 @@ debug_dump_flags(const struct debug_named_value *names,
|
||||
else
|
||||
first = 0;
|
||||
|
||||
snprintf(rest, sizeof(rest), "0x%08lx", value);
|
||||
util_snprintf(rest, sizeof(rest), "0x%08lx", value);
|
||||
strncat(output, rest, sizeof(output));
|
||||
}
|
||||
|
||||
|
@@ -166,8 +166,8 @@
|
||||
#include <config.h>
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#define vsnprintf rpl_vsnprintf
|
||||
#define snprintf rpl_snprintf
|
||||
#define vsnprintf util_vsnprintf
|
||||
#define snprintf util_snprintf
|
||||
#define HAVE_VSNPRINTF 0
|
||||
#define HAVE_SNPRINTF 0
|
||||
#define HAVE_VASPRINTF 1 /* not needed */
|
||||
@@ -445,7 +445,7 @@ static UINTMAX_T myround(LDOUBLE);
|
||||
static LDOUBLE mypow10(int);
|
||||
|
||||
int
|
||||
rpl_vsnprintf(char *str, size_t size, const char *format, va_list args)
|
||||
util_vsnprintf(char *str, size_t size, const char *format, va_list args)
|
||||
{
|
||||
LDOUBLE fvalue;
|
||||
INTMAX_T value;
|
||||
@@ -1404,7 +1404,7 @@ mymemcpy(void *dst, void *src, size_t len)
|
||||
#endif /* NEED_MYMEMCPY */
|
||||
|
||||
int
|
||||
rpl_vasprintf(char **ret, const char *format, va_list ap)
|
||||
util_vasprintf(char **ret, const char *format, va_list ap)
|
||||
{
|
||||
size_t size;
|
||||
int len;
|
||||
@@ -1422,10 +1422,10 @@ rpl_vasprintf(char **ret, const char *format, va_list ap)
|
||||
#if !HAVE_SNPRINTF
|
||||
#if HAVE_STDARG_H
|
||||
int
|
||||
rpl_snprintf(char *str, size_t size, const char *format, ...)
|
||||
util_snprintf(char *str, size_t size, const char *format, ...)
|
||||
#else
|
||||
int
|
||||
rpl_snprintf(va_alist) va_dcl
|
||||
util_snprintf(va_alist) va_dcl
|
||||
#endif /* HAVE_STDARG_H */
|
||||
{
|
||||
#if !HAVE_STDARG_H
|
||||
@@ -1449,10 +1449,10 @@ rpl_snprintf(va_alist) va_dcl
|
||||
#if !HAVE_ASPRINTF
|
||||
#if HAVE_STDARG_H
|
||||
int
|
||||
rpl_asprintf(char **ret, const char *format, ...)
|
||||
util_asprintf(char **ret, const char *format, ...)
|
||||
#else
|
||||
int
|
||||
rpl_asprintf(va_alist) va_dcl
|
||||
util_asprintf(va_alist) va_dcl
|
||||
#endif /* HAVE_STDARG_H */
|
||||
{
|
||||
#if !HAVE_STDARG_H
|
||||
|
63
src/gallium/auxiliary/util/u_string.h
Normal file
63
src/gallium/auxiliary/util/u_string.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Platform independent functions for string manipulation.
|
||||
*
|
||||
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
|
||||
*/
|
||||
|
||||
#ifndef U_STRING_H_
|
||||
#define U_STRING_H_
|
||||
|
||||
#ifndef WIN32
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
int util_vsnprintf(char *, size_t, const char *, va_list);
|
||||
int util_snprintf(char *str, size_t size, const char *format, ...);
|
||||
#else
|
||||
#define util_vsnprintf vsnprintf
|
||||
#define util_snprintf snprintf
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* U_STRING_H_ */
|
@@ -33,6 +33,7 @@
|
||||
#include "i915_fpc.h"
|
||||
|
||||
#include "pipe/p_shader_tokens.h"
|
||||
#include "util/u_string.h"
|
||||
#include "tgsi/util/tgsi_parse.h"
|
||||
#include "tgsi/util/tgsi_dump.h"
|
||||
|
||||
@@ -122,7 +123,7 @@ i915_program_error(struct i915_fp_compile *p, const char *msg, ...)
|
||||
|
||||
debug_printf("i915_program_error: ");
|
||||
va_start( args, msg );
|
||||
vsprintf( buffer, msg, args );
|
||||
util_vsnprintf( buffer, sizeof(buffer), msg, args );
|
||||
va_end( args );
|
||||
debug_printf(buffer);
|
||||
debug_printf("\n");
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "pipe/p_util.h"
|
||||
#include "pipe/p_winsys.h"
|
||||
#include "util/u_string.h"
|
||||
|
||||
#include "i915_reg.h"
|
||||
#include "i915_context.h"
|
||||
@@ -78,7 +79,7 @@ i915_get_name( struct pipe_screen *pscreen )
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(buffer, "i915 (chipset: %s)", chipset);
|
||||
util_snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "pipe/p_util.h"
|
||||
#include "pipe/p_winsys.h"
|
||||
#include "util/u_string.h"
|
||||
|
||||
#include "brw_context.h"
|
||||
#include "brw_screen.h"
|
||||
@@ -66,7 +67,7 @@ brw_get_name( struct pipe_screen *screen )
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(buffer, "i965 (chipset: %s)", chipset);
|
||||
util_snprintf(buffer, sizeof(buffer), "i965 (chipset: %s)", chipset);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#ifndef PIPE_FORMAT_H
|
||||
#define PIPE_FORMAT_H
|
||||
|
||||
#include <stdio.h> /* for sprintf */
|
||||
#include "util/u_string.h"
|
||||
|
||||
#include "p_compiler.h"
|
||||
#include "p_debug.h"
|
||||
@@ -367,7 +367,7 @@ static INLINE char *pf_sprint_name( char *str, enum pipe_format format )
|
||||
strcat( str, "S" );
|
||||
break;
|
||||
}
|
||||
sprintf( &str[strlen( str )], "%u", size * scale );
|
||||
util_snprintf( &str[strlen( str )], 32, "%u", size * scale );
|
||||
}
|
||||
if (i != 0) {
|
||||
strcat( str, "_" );
|
||||
|
@@ -138,14 +138,6 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
|
||||
#define GETENV( X ) debug_get_option( X, NULL )
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
int rpl_vsnprintf(char *, size_t, const char *, va_list);
|
||||
int rpl_snprintf(char *str, size_t size, const char *format, ...);
|
||||
#define vsnprintf rpl_vsnprintf
|
||||
#define snprintf rpl_snprintf
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Return memory on given byte alignment
|
||||
*/
|
||||
|
Reference in New Issue
Block a user