[Toybox] [PATCH] diff: put temporary file in $TMPDIR or /tmp

enh enh at google.com
Thu May 21 17:53:49 UTC 2026


ping?

On Mon, May 18, 2026 at 5:39 PM Cole Faust <colefaust at google.com> wrote:
>
> In android, we're seeing diff fail during the build, because we use a read-only source tree, and diff creates tempfiles in the current directory. Move the tempfiles to $TMPDIR or /tmp.
>
> diff --git a/lib/xwrap.c b/lib/xwrap.c
> index 6a910230..9bf108a9 100644
> --- a/lib/xwrap.c
> +++ b/lib/xwrap.c
> @@ -483,7 +483,7 @@ int xtempfile(char *name, char **tempname)
>    int fd;
>
>    *tempname = xmprintf("%s%s", name, "XXXXXX");
> -  if(-1 == (fd = mkstemp(*tempname))) error_exit("no temp file");
> +  if(-1 == (fd = mkstemp(*tempname))) error_exit("no temp file: %s", strerror(errno));
>
>    return fd;
>  }
> diff --git a/toys/pending/diff.c b/toys/pending/diff.c
> index 00d0122f..21bf8dd3 100644
> --- a/toys/pending/diff.c
> +++ b/toys/pending/diff.c
> @@ -348,10 +348,12 @@ static int *diff(char **files)
>
>    for (i = 0; i < 2; i++) {
>      if ((j = !strcmp(files[i], "-")) || S_ISFIFO(TT.st[i].st_mode)) {
> +      char *tmp = xmprintf("%s/fifo", getenv("TMPDIR") ? : "/tmp");
>        char *tmp_name;
>        int srcfd = j ? 0 : open(files[i], O_RDONLY),
> -        tmpfd = xtempfile("fifo", &tmp_name);
> +        tmpfd = xtempfile(tmp, &tmp_name);
>
> +      free(tmp);
>        unlink(tmp_name);
>        free(tmp_name);
>



More information about the Toybox mailing list