From: Timothy Arceri Date: Mon, 26 Aug 2019 00:23:11 +0000 (+1000) Subject: mesa: add copy_string() helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=628d34fddd1e7fe8f31df4d4a725aec3aed3bed8;p=mesa.git mesa: add copy_string() helper This will be used by the various ARB_shading_language_include functions in the following patches. Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Witold Baryluk --- diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 7fe3d0d0a0e..88ad476bdb2 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -3309,6 +3309,26 @@ _mesa_lookup_shader_include(struct gl_context *ctx, char *path) return sh_incl_ht_entry ? sh_incl_ht_entry->shader_source : NULL; } +static char * +copy_string(struct gl_context *ctx, const char *str, int str_len, + const char *caller) +{ + if (!str) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(NULL string)", caller); + return NULL; + } + + char *cp; + if (str_len == -1) + cp = strdup(str); + else { + cp = calloc(sizeof(char), str_len + 1); + memcpy(cp, str, str_len); + } + + return cp; +} + GLvoid GLAPIENTRY _mesa_NamedStringARB(GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string)