Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ksh compatibility: initial value of $_



On Fri, Mar 31, 2023 at 7:32 AM Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
> +++ b/Src/init.c
> @@ -1084,9 +1084,18 @@ setupvals(char *cmd, char *runscript, char *zsh_name)
> +    zunderscore = getenv("_");
> +    if (zunderscore) {
> +       zunderscore = metafy(ztrdup(zunderscore), -1, META_REALLOC);
> +       underscoreused = strlen(zunderscore) + 1;
> +       underscorelen = (underscoreused + 31) & ~31;
> +       zunderscore = (char *)zrealloc(zunderscore, underscorelen);
> +    }
> +    else {
> +       zunderscore  = (char *)zalloc(underscorelen = 32);
> +       underscoreused = 1;
> +       *zunderscore = '\0';
> +    }

Is there a simple way to call setunderscore() here instead of
duplicating most of it?  The complication mostly seems to be that
metafy() doesn't handle a NULL string, so we can't just
metafy(getenv()).

> +       zunderscore = metafy(ztrdup(zunderscore), -1, META_REALLOC);

This at least could just be

       zunderscore = metafy(zunderscore, -1, META_ALLOC);

??




Messages sorted by: Reverse Date, Date, Thread, Author