Hi Pekka, On 18 June 2018 at 15:40, Pekka Paalanen <ppaala...@gmail.com> wrote: > From: Daniel Stone <dani...@collabora.com> > > Rather than having a hardcoded dependency on the build-directory layout, > use an explicit module-map environment variable, which rewrites requests > for modules and helper/libexec binaries to specific paths. > > This will help with migration to Meson where setting up the paths > according to autotools would be painful and unnecessary. > Surely one didn't need a build system, to make nice improvements. I guess, sometimes, tools do need to give us a wake-up call.
> +WL_EXPORT size_t > +weston_module_path_from_env(const char *name, char *path, size_t path_len) > +{ > + const char *mapping = getenv("WESTON_MODULE_MAP"); > + const char *end; > + strlen(name) once and use it throughout? > + if (!mapping) > + return 0; > + > + end = mapping + strlen(mapping); > + while (mapping < end && *mapping) { > + const char *filename, *next; > + > + /* early out: impossibly short string */ > + if ((size_t)(end - mapping) < strlen(name) + 1) > + return 0; > + > + filename = &mapping[strlen(name) + 1]; > + next = strchrnul(mapping, ';'); > + > + if (strncmp(mapping, name, strlen(name)) == 0 && > + mapping[strlen(name)] == '=') { > + size_t file_len = next - filename; /* no trailing NUL > */ > + if (file_len >= path_len) > + return 0; > + strncpy(path, filename, file_len); > + path[file_len] = '\0'; A simple stat() can, more or less, ensure that we're not giving random rubbish to the caller. Worth it, or more of an overkill? -Emil _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel