Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
"does not contain a file descriptor" (Re: cat as a builtin command)
- X-seq: zsh-workers 33087
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: "does not contain a file descriptor" (Re: cat as a builtin command)
- Date: Mon, 01 Sep 2014 12:44:03 -0700
- In-reply-to: <140901113940.ZM2031@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <BLU436-SMTP2045383EF41756D3376DB3CF4DB0@phx.gbl> <20140901075315.GA5908@localhost.localdomain> <140901113940.ZM2031@torch.brasslantern.com>
On Sep 1, 11:39am, Bart Schaefer wrote:
}
} torch% exec {fd}<&-
} zsh: parameter fd does not contain a file descriptor
}
} It appears that only an UNSET parameter name triggers the "does not
} contain" error; a set-but-empty parameter is treated as 0 and closes
} standard input
Do we really want that behavior? Or the following behavior?
torch% declare fd="12+7"
torch% exec {fd}<&-
zsh: failed to close file descriptor 19: bad file descriptor
Patch below makes this somewhat more rigorous; but if the parameter is
declared as an integer, then even its string value is zero when no value
has been assigned, so the original problem can't be completely avoided.
(As far as I can tell, perhaps I'm wrong?)
I won't commit this without getting feedback, because it doesn't work
correctly with parameters declared as integers in bases other than 10
(also 8 if you set OCTAL_ZEROS, and also 16 if you set C_BASES). So
other suggestions are welcome ... or we can just document that all file
descriptors must be base-10 integers, in which case we should change the
base from 0 to 10 in the zstrtol() call.
diff --git a/Src/exec.c b/Src/exec.c
index bf50d0f..7fb51bc 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3060,8 +3060,9 @@ execcmd(Estate state, int input, int output, int how, int last1)
} else if (v->pm->node.flags & PM_READONLY) {
bad = 2;
} else {
- fn->fd1 = (int)getintvalue(v);
- if (errflag)
+ char *s = getstrvalue(v), *t;
+ fn->fd1 = zstrtol(s, &t, 0);
+ if (errflag || s == t || *t)
bad = 1;
else if (fn->fd1 <= max_zsh_fd) {
if (fn->fd1 >= 10 &&
Messages sorted by:
Reverse Date,
Date,
Thread,
Author