mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-05 15:16:19 +02:00
50355: documentation and return status consistency in zsh/system module
This commit is contained in:
parent
6a6e358baf
commit
61f35bb626
|
@ -1,3 +1,9 @@
|
||||||
|
2022-06-11 Bart Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
|
* 50355: Doc/Zsh/mod_system.yo, Src/Modules/system.c: make return
|
||||||
|
status values of sysopen consistent with other sys* functions,
|
||||||
|
make ERRNO values consistent for all, and update documentation
|
||||||
|
|
||||||
2022-06-11 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
2022-06-11 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||||
|
|
||||||
* 50356: Etc/FAQ.yo: work around a yodl bug (mishandling of \'e)
|
* 50356: Etc/FAQ.yo: work around a yodl bug (mishandling of \'e)
|
||||||
|
|
|
@ -74,6 +74,11 @@ truncate file to size 0
|
||||||
)
|
)
|
||||||
enditem()
|
enditem()
|
||||||
|
|
||||||
|
A return status of 0 indicates the descriptor was successfully opened,
|
||||||
|
otherwise an error message is printed, and 1 is returned for an error
|
||||||
|
in the parameters to the command, or 2 is returned for a system error.
|
||||||
|
The parameter tt(ERRNO) is nonzero for system errors.
|
||||||
|
|
||||||
To close the file, use one of the following:
|
To close the file, use one of the following:
|
||||||
|
|
||||||
example(tt(exec {)var(fd)tt(}<&-)
|
example(tt(exec {)var(fd)tt(}<&-)
|
||||||
|
@ -123,11 +128,11 @@ error for which a message is printed to standard error.
|
||||||
)
|
)
|
||||||
item(2)(
|
item(2)(
|
||||||
There was an error on the read, or on polling the input file descriptor
|
There was an error on the read, or on polling the input file descriptor
|
||||||
for a timeout. The parameter tt(ERRNO) gives the error.
|
for a timeout. The parameter tt(ERRNO) identifies the error.
|
||||||
)
|
)
|
||||||
item(3)(
|
item(3)(
|
||||||
Data were successfully read, but there was an error writing them
|
Data were successfully read, but there was an error writing them
|
||||||
to var(outfd). The parameter tt(ERRNO) gives the error.
|
to var(outfd). The parameter tt(ERRNO) identifies the error.
|
||||||
)
|
)
|
||||||
item(4)(
|
item(4)(
|
||||||
The attempt to read timed out. Note this does not set tt(ERRNO) as this
|
The attempt to read timed out. Note this does not set tt(ERRNO) as this
|
||||||
|
@ -147,6 +152,11 @@ expression. The tt(-u) option allows the file descriptor to be specified. By
|
||||||
default the offset is specified relative to the start or the file but, with the
|
default the offset is specified relative to the start or the file but, with the
|
||||||
tt(-w) option, it is possible to specify that the offset should be relative to
|
tt(-w) option, it is possible to specify that the offset should be relative to
|
||||||
the current position or the end of the file.
|
the current position or the end of the file.
|
||||||
|
|
||||||
|
The return status may be 0 for success, 1 for an error in the parameters
|
||||||
|
to the command, or 2 for an error on the seek; no error message is
|
||||||
|
printed in the last case, but the parameter tt(ERRNO) reflects
|
||||||
|
the error that occurred.
|
||||||
)
|
)
|
||||||
item(tt(syswrite) [ tt(-c) var(countvar) ] [ tt(-o) var(outfd) ] var(data))(
|
item(tt(syswrite) [ tt(-c) var(countvar) ] [ tt(-o) var(outfd) ] var(data))(
|
||||||
The data (a single string of bytes) are written to the file descriptor
|
The data (a single string of bytes) are written to the file descriptor
|
||||||
|
@ -166,7 +176,7 @@ returning early.
|
||||||
|
|
||||||
The return status may be 0 for success, 1 for an error in the parameters
|
The return status may be 0 for success, 1 for an error in the parameters
|
||||||
to the command, or 2 for an error on the write; no error message is
|
to the command, or 2 for an error on the write; no error message is
|
||||||
printed in the last case, but the parameter tt(ERRNO) will reflect
|
printed in the last case, but the parameter tt(ERRNO) reflects
|
||||||
the error that occurred.
|
the error that occurred.
|
||||||
)
|
)
|
||||||
xitem(tt(zsystem flock) [ tt(-t) var(timeout) ] [ tt(-i) var(interval) ] [ tt(-f) var(var) ] [tt(-er)] var(file))
|
xitem(tt(zsystem flock) [ tt(-t) var(timeout) ] [ tt(-i) var(interval) ] [ tt(-f) var(var) ] [tt(-er)] var(file))
|
||||||
|
|
|
@ -74,6 +74,8 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
int infd = 0, outfd = -1, bufsize = SYSREAD_BUFSIZE, count;
|
int infd = 0, outfd = -1, bufsize = SYSREAD_BUFSIZE, count;
|
||||||
char *outvar = NULL, *countvar = NULL, *inbuf;
|
char *outvar = NULL, *countvar = NULL, *inbuf;
|
||||||
|
|
||||||
|
errno = 0; /* Distinguish non-system errors */
|
||||||
|
|
||||||
/* -i: input file descriptor if not stdin */
|
/* -i: input file descriptor if not stdin */
|
||||||
if (OPT_ISSET(ops, 'i')) {
|
if (OPT_ISSET(ops, 'i')) {
|
||||||
infd = getposint(OPT_ARG(ops, 'i'), nam);
|
infd = getposint(OPT_ARG(ops, 'i'), nam);
|
||||||
|
@ -238,6 +240,8 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
int outfd = 1, len, count, totcount;
|
int outfd = 1, len, count, totcount;
|
||||||
char *countvar = NULL;
|
char *countvar = NULL;
|
||||||
|
|
||||||
|
errno = 0; /* Distinguish non-system errors */
|
||||||
|
|
||||||
/* -o: output file descriptor if not stdout */
|
/* -o: output file descriptor if not stdout */
|
||||||
if (OPT_ISSET(ops, 'o')) {
|
if (OPT_ISSET(ops, 'o')) {
|
||||||
outfd = getposint(OPT_ARG(ops, 'o'), nam);
|
outfd = getposint(OPT_ARG(ops, 'o'), nam);
|
||||||
|
@ -303,6 +307,13 @@ static struct { const char *name; int oflag; } openopts[] = {
|
||||||
{ "trunc", O_TRUNC }
|
{ "trunc", O_TRUNC }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return values of bin_sysopen:
|
||||||
|
* 0 Success
|
||||||
|
* 1 Error in parameters to command
|
||||||
|
* 2 Error on open, ERRNO set by system
|
||||||
|
*/
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static int
|
static int
|
||||||
bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
|
bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
|
@ -319,6 +330,8 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
int fdflags = 0;
|
int fdflags = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
errno = 0; /* Distinguish non-system errors */
|
||||||
|
|
||||||
if (!OPT_ISSET(ops, 'u')) {
|
if (!OPT_ISSET(ops, 'u')) {
|
||||||
zwarnnam(nam, "file descriptor not specified");
|
zwarnnam(nam, "file descriptor not specified");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -374,12 +387,12 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
zwarnnam(nam, "can't open file %s: %e", *args, errno);
|
zwarnnam(nam, "can't open file %s: %e", *args, errno);
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
moved_fd = (explicit > -1) ? redup(fd, explicit) : movefd(fd);
|
moved_fd = (explicit > -1) ? redup(fd, explicit) : movefd(fd);
|
||||||
if (moved_fd == -1) {
|
if (moved_fd == -1) {
|
||||||
zwarnnam(nam, "can't open file %s", *args);
|
zwarnnam(nam, "can't open file %s", *args);
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FD_CLOEXEC
|
#ifdef FD_CLOEXEC
|
||||||
|
@ -423,6 +436,8 @@ bin_sysseek(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
char *whence;
|
char *whence;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
|
|
||||||
|
errno = 0; /* Distinguish non-system errors */
|
||||||
|
|
||||||
/* -u: file descriptor if not stdin */
|
/* -u: file descriptor if not stdin */
|
||||||
if (OPT_ISSET(ops, 'u')) {
|
if (OPT_ISSET(ops, 'u')) {
|
||||||
fd = getposint(OPT_ARG(ops, 'u'), nam);
|
fd = getposint(OPT_ARG(ops, 'u'), nam);
|
||||||
|
|
Loading…
Reference in New Issue