From f8f9a1b620d31d1a59855fd502caed325d4a324f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 7 Jan 2009 12:02:06 +0000 Subject: [PATCH] mesa: Add _mesa_snprintf. On Windows snprintf is renamed as _snprintf. --- src/mesa/main/imports.c | 12 ++++++++++++ src/mesa/main/imports.h | 3 +++ src/mesa/shader/slang/slang_codegen.c | 2 +- src/mesa/shader/slang/slang_emit.c | 4 ++-- src/mesa/shader/slang/slang_link.c | 8 ++++---- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 7231fa699cb..27d6df2f85a 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -909,6 +909,18 @@ _mesa_sprintf( char *str, const char *fmt, ... ) return r; } +/** Wrapper around vsnprintf() */ +int +_mesa_snprintf( char *str, size_t size, const char *fmt, ... ) +{ + int r; + va_list args; + va_start( args, fmt ); + r = vsnprintf( str, size, fmt, args ); + va_end( args ); + return r; +} + /** Wrapper around printf(), using vsprintf() for the formatting. */ void _mesa_printf( const char *fmtString, ... ) diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index d91a1366b07..52d679cadd7 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -752,6 +752,9 @@ _mesa_strtod( const char *s, char **end ); extern int _mesa_sprintf( char *str, const char *fmt, ... ); +extern int +_mesa_snprintf( char *str, size_t size, const char *fmt, ... ); + extern void _mesa_printf( const char *fmtString, ... ); diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 7a2690b551d..cc6d71478d6 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1973,7 +1973,7 @@ _slang_make_array_constructor(slang_assemble_ctx *A, slang_operation *oper) */ slang_variable *p = slang_variable_scope_grow(fun->parameters); char name[10]; - snprintf(name, sizeof(name), "p%d", i); + _mesa_snprintf(name, sizeof(name), "p%d", i); p->a_name = slang_atom_pool_atom(A->atoms, name); p->type.qualifier = SLANG_QUAL_CONST; p->type.specifier.type = baseType; diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 35d323118e3..3a837c9c10e 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -2096,8 +2096,8 @@ emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n) if (index < 0) { /* error */ char s[100]; - snprintf(s, sizeof(s), "Undefined variable '%s'", - (char *) n->Var->a_name); + _mesa_snprintf(s, sizeof(s), "Undefined variable '%s'", + (char *) n->Var->a_name); slang_info_log_error(emitInfo->log, s); return NULL; } diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index b2fd9554a66..108d11c7df4 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -137,15 +137,15 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog) } if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_CENTROID)) { char msg[100]; - snprintf(msg, sizeof(msg), - "centroid modifier mismatch for '%s'", var->Name); + _mesa_snprintf(msg, sizeof(msg), + "centroid modifier mismatch for '%s'", var->Name); link_error(shProg, msg); return GL_FALSE; } if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_INVARIANT)) { char msg[100]; - snprintf(msg, sizeof(msg), - "invariant modifier mismatch for '%s'", var->Name); + _mesa_snprintf(msg, sizeof(msg), + "invariant modifier mismatch for '%s'", var->Name); link_error(shProg, msg); return GL_FALSE; } -- 2.30.2