summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-15 07:00:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-15 07:00:59 -0700
commit0a45facfe39ff943a0e290f4b6d5ac6481bb31f4 (patch)
tree6affa666e5729ab36b342da0b1a4baefb1487411 /stream.c
parent2bb9d6a776f6a8f213f1af304c0ff1a570d0424a (diff)
downloadtxr-0a45facfe39ff943a0e290f4b6d5ac6481bb31f4.tar.gz
txr-0a45facfe39ff943a0e290f4b6d5ac6481bb31f4.tar.bz2
txr-0a45facfe39ff943a0e290f4b6d5ac6481bb31f4.zip
subprocesses: diagnose streams with no fileno.
* stream.c (fds_subst): Check that stream_fd returns a non-integer; if so, put out a more meaningful diagnostic, rather than allowing c_num to generate a "nil is not an integer" error. Also, let's incorporate the self string into the existing failed dup diagnostic.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/stream.c b/stream.c
index cc5a26f8..9d1d3a5f 100644
--- a/stream.c
+++ b/stream.c
@@ -4247,7 +4247,13 @@ static void fds_init(struct save_fds *fds)
static int fds_subst(val stream, int fd_std, val self)
{
- int fd_orig = c_num(stream_fd(stream), self);
+ val sfd = stream_fd(stream);
+ int fd_orig = if3(integerp(sfd), c_num(sfd, self), INT_MIN);
+
+
+ if (fd_orig == INT_MIN)
+ uw_throwf(file_error_s, lit("~a: (fileno ~s) is ~s, which is unusable"),
+ self, stream, sfd, nao);
if (fd_orig == fd_std)
return -1;
@@ -4260,8 +4266,8 @@ static int fds_subst(val stream, int fd_std, val self)
return fd_dup;
}
- uw_throwf(file_error_s, lit("failed to duplicate file descriptor: ~d/~s"),
- num(errno), errno_to_str(errno), nao);
+ uw_throwf(file_error_s, lit("~a: failed to duplicate file descriptor: ~d/~s"),
+ self, num(errno), errno_to_str(errno), nao);
}
}