On Mon, Oct 27, 2014 at 03:15:56PM +0300, Ilya Verbin wrote:
> + bool use_alloca;
> + const char *ld_lib_path = getenv (LD_LIBRARY_PATH_ENV);
> + const char *mic_lib_path = getenv (MIC_LD_LIBRARY_PATH_ENV);
> + char *mic_lib_path_new;
> + size_t len;
> +
> + if (!ld_lib_path)
> + return;
> +
> + len = (mic_lib_path ? strlen (mic_lib_path) : 0) + strlen (ld_lib_path) +
> 2;
> + use_alloca = len <= 2048;
> +
> + mic_lib_path_new = (char *) (use_alloca ? alloca (len) : malloc (len));
> + if (!mic_lib_path_new)
> + {
> + fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
> + exit (1);
> + }
> +
> + if (!mic_lib_path)
> + strcpy (mic_lib_path_new, ld_lib_path);
> + else
> + sprintf (mic_lib_path_new, "%s:%s", mic_lib_path, ld_lib_path);
Oh, one more point, if mic_lib_path is NULL, what is the point
to do the alloca/malloc and string copying? Can't you just
setenv (MIC_LD_LIBRARY_PATH_ENV, ld_lib_path, 1);
in that case early?
Otherwise LGTM.
Jakub