Skip to content

Commit

Permalink
Replace ERRIO with STDERR_FILENO
Browse files Browse the repository at this point in the history
While working on fixing issue #1079 I noticed the ERRIO symbol that is
simply an obscure alias for the standard STDERR_FILENO symbol. So replace
the former with the latter.

If we ever get a build failure on a system that does not provide the
industry standard STDERR_FILENO symbol we can implement a build time test
for its availability and provide a fallback. Although in that case we
should also ensure the same magic constant via a compile time symbol is
also used in the SFIO code. Hint: At the moment ERRIO is unique to the
ksh code (i.e., not used in the SFIO code) and is not defined in terms
of a SFIO constant.

Related #1079
  • Loading branch information
krader1961 committed Dec 20, 2018
1 parent 5b84cb1 commit 6cd0b41
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int ed_window(void) {
//
void ed_flush(Edit_t *ep) {
int n = ep->e_outptr - ep->e_outbase;
int fd = ERRIO;
int fd = STDERR_FILENO;

if (n <= 0) return;
write(fd, ep->e_outbase, (unsigned)n);
Expand All @@ -282,7 +282,7 @@ void ed_flush(Edit_t *ep) {
//
// Send the bell character ^G to the terminal.
//
void ed_ringbell(void) { write(ERRIO, bellchr, 1); }
void ed_ringbell(void) { write(STDERR_FILENO, bellchr, 1); }

//
// Send a carriage return line feed to the terminal.
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int ed_emacsread(void *context, int fd, char *buff, int scend, int reedit) {
Prompt = prompt;
ep->screen = Screen;
ep->lastdraw = FINAL;
if (tty_raw(ERRIO, 0) < 0) {
if (tty_raw(STDERR_FILENO, 0) < 0) {
return reedit ? reedit : ed_read(context, fd, buff, scend, 0);
}
raw = 1;
Expand Down Expand Up @@ -207,7 +207,7 @@ int ed_emacsread(void *context, int fd, char *buff, int scend, int reedit) {
draw(ep, FINAL);
ed_flush(ep->ed);
}
tty_cooked(ERRIO);
tty_cooked(STDERR_FILENO);
if (i == UEOF) return 0; // EOF
return -1; // some other error
}
Expand Down Expand Up @@ -266,7 +266,7 @@ int ed_emacsread(void *context, int fd, char *buff, int scend, int reedit) {
}
case EOFCHAR: {
ed_flush(ep->ed);
tty_cooked(ERRIO);
tty_cooked(STDERR_FILENO);
return 0;
}
case '\t': {
Expand Down Expand Up @@ -600,7 +600,7 @@ int ed_emacsread(void *context, int fd, char *buff, int scend, int reedit) {
*out = '\0';
}
draw(ep, FINAL);
tty_cooked(ERRIO);
tty_cooked(STDERR_FILENO);
if (ed->e_nlist) {
ed->e_nlist = 0;
stakset(ed->e_stkptr, ed->e_stkoff);
Expand Down
8 changes: 5 additions & 3 deletions src/cmd/ksh93/edit/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
shbuf[reedit] = 0;

// Set raw mode.
if (tty_raw(ERRIO, 0) < 0) return reedit ? reedit : ed_read(context, fd, shbuf, nchar, 0);
if (tty_raw(STDERR_FILENO, 0) < 0) {
return reedit ? reedit : ed_read(context, fd, shbuf, nchar, 0);
}
i = last_virt - 1;

// Initialize some things.
Expand Down Expand Up @@ -246,7 +248,7 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
sync_cursor(vp);
}
virtual[0] = '\0';
tty_cooked(ERRIO);
tty_cooked(STDERR_FILENO);

if (i == UEOF) return 0; // EOF
if (i == UINTR) return -1; // interrupt
Expand All @@ -263,7 +265,7 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) {
vigetline(vp, APPEND);
if (vp->ed->e_multiline) cursor(vp, last_phys);
// Add a new line if user typed unescaped \n to cause the shell to process the line.
tty_cooked(ERRIO);
tty_cooked(STDERR_FILENO);
if (ed->e_nlist) {
ed->e_nlist = 0;
stkset(ed->sh->stk, ed->e_stkptr, ed->e_stkoff);
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/ksh93/include/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
#define IOBSIZE (SF_BUFSIZE * _ast_sizeof_pointer)
#define IOMAXTRY 20

// Used for output of shell errors.
#define ERRIO 2

#define IOREAD 001
#define IOWRITE 002
#define IODUP 004
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/ksh93/sh/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2306,15 +2306,15 @@ static_fn void sftrack(Sfio_t *sp, int flag, void *data) {
#ifdef DEBUG
if (flag == SF_READ || flag == SF_WRITE) {
char *z = fmtbase((long)getpid(), 0, 0);
write(ERRIO, z, strlen(z));
write(ERRIO, ": ", 2);
write(ERRIO, "attempt to ", 11);
write(STDERR_FILENO, z, strlen(z));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, "attempt to ", 11);
if (flag == SF_READ) {
write(ERRIO, "read from", 9);
write(STDERR_FILENO, "read from", 9);
} else {
write(ERRIO, "write to", 8);
write(STDERR_FILENO, "write to", 8);
}
write(ERRIO, " locked stream\n", 15);
write(STDERR_FILENO, " locked stream\n", 15);
return;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int sh_main(int ac, char *av[], Shinit_f userinit) {
// Decide whether shell is interactive.
if (!sh_isoption(shp, SH_INTERACTIVE) && !sh_isoption(shp, SH_TFLAG) &&
!sh_isoption(shp, SH_CFLAG) && sh_isoption(shp, SH_SFLAG) && tty_check(0) &&
tty_check(ERRIO)) {
tty_check(STDERR_FILENO)) {
sh_onoption(shp, SH_INTERACTIVE);
}
if (sh_isoption(shp, SH_INTERACTIVE)) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ int sh_exec(Shell_t *shp, const Shnode_t *t, int flags) {
shp->exitval = (*shp->bltinfun)(argn, com, (void *)bp);
sfsync(NULL);
}
if (error_info.flags & ERROR_INTERACTIVE) tty_check(ERRIO);
if (error_info.flags & ERROR_INTERACTIVE) tty_check(STDERR_FILENO);
((Shnode_t *)t)->com.comstate = shp->bltindata.data;
bp->data = (void *)save_data;
if (shp->exitval && errno == EINTR && shp->lastsig) {
Expand Down

0 comments on commit 6cd0b41

Please sign in to comment.