pub fn getherestr(fn_: &redir) -> i32Expand description
Port of int getherestr(struct redir *fn) from Src/exec.c:4655.
C body:
char *s, *t;
int fd, len;
t = fn->name;
singsub(&t);
untokenize(t);
unmetafy(t, &len);
if (!(fn->flags & REDIRF_FROM_HEREDOC))
t[len++] = '\n';
if ((fd = gettempfile(NULL, 1, &s)) < 0)
return -1;
write_loop(fd, t, len);
close(fd);
fd = open(s, O_RDONLY | O_NOCTTY);
unlink(s);
return fd;Materialise a <<< herestring or unprocessed-here-doc body into a
tempfile, then re-open read-only and unlink — gives the consumer a
read fd whose backing file is already cleaned up.