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 <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
This commit is contained in:
Timothy Arceri 2019-08-26 10:23:11 +10:00
parent 8acab84f93
commit 628d34fddd
1 changed files with 20 additions and 0 deletions

View File

@ -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)