summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/shaderapi.c
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2016-11-15 11:53:33 -0800
committerKenneth Graunke <[email protected]>2016-11-17 14:14:37 -0800
commit9bfee7047b70cb0aa026ca9536465762f96cb2b1 (patch)
tree81bb846aef35496b6249cab8b3bde0ab07167ea8 /src/mesa/main/shaderapi.c
parentca76e6b5213c92432b9f3a641cb26f5861d53e09 (diff)
mesa: Drop PATH_MAX usage.
GNU/Hurd does not define PATH_MAX since it doesn't have such arbitrary limitation, so this failed to compile. Apparently glibc does not enforce PATH_MAX restrictions anyway, so it's kind of a hoax: https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html MSVC uses a different name (_MAX_PATH) as well, which is annoying. We don't really need it. We can simply asprintf() the filenames. If the filename exceeds an OS path limit, presumably fopen() will fail, and we already check that. (We actually use ralloc_asprintf because Mesa provides that everywhere, and it doesn't look like we've provided an implementation of GNU's asprintf() for all platforms.) Fixes the build on GNU/Hurd. Cc: "13.0" <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98632 Signed-off-by: Samuel Thibault <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/mesa/main/shaderapi.c')
-rw-r--r--src/mesa/main/shaderapi.c37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 5db41375006..627bc732183 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -60,11 +60,6 @@
#include "util/hash_table.h"
#include "util/mesa-sha1.h"
-#ifdef _MSC_VER
-#include <stdlib.h>
-#define PATH_MAX _MAX_PATH
-#endif
-
/**
* Return mask of GLSL_x flags by examining the MESA_GLSL env var.
*/
@@ -112,13 +107,6 @@ _mesa_get_shader_capture_path(void)
if (!read_env_var) {
path = getenv("MESA_SHADER_CAPTURE_PATH");
read_env_var = true;
- if (path &&
- strlen(path) > PATH_MAX - strlen("/fp-4294967295.shader_test")) {
- GET_CURRENT_CONTEXT(ctx);
- _mesa_warning(ctx, "MESA_SHADER_CAPTURE_PATH too long; ignoring "
- "request to capture shaders");
- path = NULL;
- }
}
return path;
@@ -1101,11 +1089,8 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
const char *capture_path = _mesa_get_shader_capture_path();
if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) {
FILE *file;
- char filename[PATH_MAX];
-
- _mesa_snprintf(filename, sizeof(filename), "%s/%u.shader_test",
- capture_path, shProg->Name);
-
+ char *filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
+ capture_path, shProg->Name);
file = fopen(filename, "w");
if (file) {
fprintf(file, "[require]\nGLSL%s >= %u.%02u\n",
@@ -1124,6 +1109,8 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
} else {
_mesa_warning(ctx, "Failed to open %s", filename);
}
+
+ ralloc_free(filename);
}
if (shProg->LinkStatus == GL_FALSE &&
@@ -1618,9 +1605,9 @@ generate_sha1(const char *source, char sha_str[64])
*
* <path>/<stage prefix>_<CHECKSUM>.glsl
*/
-static void
+static char *
construct_name(const gl_shader_stage stage, const char *source,
- const char *path, char *name, unsigned length)
+ const char *path)
{
char sha[64];
static const char *types[] = {
@@ -1628,8 +1615,7 @@ construct_name(const gl_shader_stage stage, const char *source,
};
generate_sha1(source, sha);
- _mesa_snprintf(name, length, "%s/%s_%s.glsl", path, types[stage],
- sha);
+ return ralloc_asprintf(NULL, "%s/%s_%s.glsl", path, types[stage], sha);
}
/**
@@ -1638,7 +1624,6 @@ construct_name(const gl_shader_stage stage, const char *source,
static void
dump_shader(const gl_shader_stage stage, const char *source)
{
- char name[PATH_MAX];
static bool path_exists = true;
char *dump_path;
FILE *f;
@@ -1652,7 +1637,7 @@ dump_shader(const gl_shader_stage stage, const char *source)
return;
}
- construct_name(stage, source, dump_path, name, PATH_MAX);
+ char *name = construct_name(stage, source, dump_path);
f = fopen(name, "w");
if (f) {
@@ -1663,6 +1648,7 @@ dump_shader(const gl_shader_stage stage, const char *source)
_mesa_warning(ctx, "could not open %s for dumping shader (%s)", name,
strerror(errno));
}
+ ralloc_free(name);
}
/**
@@ -1672,7 +1658,6 @@ dump_shader(const gl_shader_stage stage, const char *source)
static GLcharARB *
read_shader(const gl_shader_stage stage, const char *source)
{
- char name[PATH_MAX];
char *read_path;
static bool path_exists = true;
int len, shader_size = 0;
@@ -1688,9 +1673,9 @@ read_shader(const gl_shader_stage stage, const char *source)
return NULL;
}
- construct_name(stage, source, read_path, name, PATH_MAX);
-
+ char *name = construct_name(stage, source, read_path);
f = fopen(name, "r");
+ ralloc_free(name);
if (!f)
return NULL;