mesa: add copy_string() helper
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 26 Aug 2019 00:23:11 +0000 (10:23 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 20 Nov 2019 05:05:55 +0000 (05:05 +0000)
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>
src/mesa/main/shaderapi.c

index 7fe3d0d0a0e5df2f0120a3f7eb662ac5fd4b42a7..88ad476bdb29b6da69656761e9e14bc4de125e84 100644 (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)