diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 81 |
1 files changed, 45 insertions, 36 deletions
@@ -3,7 +3,7 @@ */ /* - * Copyright (C) 1986, 1988, 1989, 1991, 1992 the Free Software Foundation, Inc. + * Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the * AWK Progamming Language. @@ -56,14 +56,14 @@ static int close_redir P((struct redirect *rp)); static int wait_any P((int interesting)); #endif static IOBUF *gawk_popen P((char *cmd, struct redirect *rp)); -static IOBUF *iop_open P((char *file, char *how)); +static IOBUF *iop_open P((const char *file, const char *how)); static int gawk_pclose P((struct redirect *rp)); -static int do_pathopen P((char *file)); -static int str2mode P((char *mode)); +static int do_pathopen P((const char *file)); +static int str2mode P((const char *mode)); static void spec_setup P((IOBUF *iop, int len, int allocate)); -static int specfdopen P((IOBUF *iop, char *name, char *mode)); -static int pidopen P((IOBUF *iop, char *name, char *mode)); -static int useropen P((IOBUF *iop, char *name, char *mode)); +static int specfdopen P((IOBUF *iop, const char *name, const char *mode)); +static int pidopen P((IOBUF *iop, const char *name, const char *mode)); +static int useropen P((IOBUF *iop, const char *name, const char *mode)); extern FILE *fdopen(); @@ -262,6 +262,9 @@ do_input() if (inrec(iop) == 0) while (interpret(expression_value) && inrec(iop) == 0) ; + /* recover any space from C based alloca */ + (void) alloca(0); + if (exiting) break; } @@ -278,10 +281,10 @@ int *errflg; register char *str; int tflag = 0; int outflag = 0; - char *direction = "to"; - char *mode; + const char *direction = "to"; + const char *mode; int fd; - char *what = NULL; + const char *what = NULL; switch (tree->type) { case Node_redirect_append: @@ -394,9 +397,13 @@ int *errflg; rp->fp = stdout; else if (fd == fileno(stderr)) rp->fp = stderr; - else - rp->fp = fdopen(fd, mode); - if (isatty(fd)) + else { + rp->fp = fdopen(fd, (char *) mode); + /* don't leak file descriptors */ + if (rp->fp == NULL) + close(fd); + } + if (rp->fp != NULL && isatty(fd)) rp->flag |= RED_NOBUF; } } @@ -589,7 +596,7 @@ close_io () static int str2mode(mode) -char *mode; +const char *mode; { int ret; @@ -605,7 +612,9 @@ char *mode; case 'a': ret = O_WRONLY|O_APPEND|O_CREAT; break; + default: + ret = 0; /* lint */ cant_happen(); } return ret; @@ -622,10 +631,10 @@ char *mode; int devopen(name, mode) -char *name, *mode; +const char *name, *mode; { int openfd = INVALID_HANDLE; - char *cp, *ptr; + const char *cp, *ptr; int flag = 0; struct stat buf; extern double strtod(); @@ -642,7 +651,7 @@ char *name, *mode; if (STREQ(name, "-")) openfd = fileno(stdin); - else if (STREQN(name, "/dev/", 5) && stat(name, &buf) == -1) { + else if (STREQN(name, "/dev/", 5) && stat((char *) name, &buf) == -1) { cp = name + 5; if (STREQ(cp, "stdin") && (flag & O_RDONLY) == O_RDONLY) @@ -701,7 +710,7 @@ int allocate; static int specfdopen(iop, name, mode) IOBUF *iop; -char *name, *mode; +const char *name, *mode; { int fd; IOBUF *tp; @@ -748,7 +757,7 @@ char *name, *mode; static int pidopen(iop, name, mode) IOBUF *iop; -char *name, *mode; +const char *name, *mode; { char tbuf[BUFSIZ]; int i; @@ -780,12 +789,12 @@ char *name, *mode; static int useropen(iop, name, mode) IOBUF *iop; -char *name, *mode; +const char *name, *mode; { char tbuf[BUFSIZ], *cp; int i; #if defined(NGROUPS_MAX) && NGROUPS_MAX > 0 -#if defined(atarist) +#if defined(atarist) || defined(__svr4__) gid_t groupset[NGROUPS_MAX]; #else int groupset[NGROUPS_MAX]; @@ -821,16 +830,16 @@ char *name, *mode; static IOBUF * iop_open(name, mode) -char *name, *mode; +const char *name, *mode; { int openfd = INVALID_HANDLE; int flag = 0; struct stat buf; IOBUF *iop; static struct internal { - char *name; + const char *name; int compare; - int (*fp)(); + int (*fp) P((IOBUF*,const char *,const char *)); IOBUF iob; } table[] = { { "/dev/fd/", 8, specfdopen }, @@ -851,12 +860,12 @@ char *name, *mode; if (STREQ(name, "-")) openfd = fileno(stdin); - else if (STREQN(name, "/dev/", 5) && stat(name, &buf) == -1) { + else if (STREQN(name, "/dev/", 5) && stat((char *) name, &buf) == -1) { int i; for (i = 0; i < devcount; i++) { if (STREQN(name, table[i].name, table[i].compare)) { - IOBUF *iop = & table[i].iob; + iop = & table[i].iob; if (iop->buf != NULL) { spec_setup(iop, 0, 0); @@ -1005,7 +1014,7 @@ gawk_pclose(rp) struct redirect *rp; { int rval, aval, fd = rp->iop->fd; - FILE *kludge = fdopen(fd, "r"); /* pclose needs FILE* w/ right fileno */ + FILE *kludge = fdopen(fd, (char *) "r"); /* pclose needs FILE* w/ right fileno */ rp->iop->fd = dup(fd); /* kludge to allow close() + pclose() */ rval = iop_close(rp->iop); @@ -1013,7 +1022,7 @@ struct redirect *rp; aval = pclose(kludge); return (rval < 0 ? rval : aval); } -#else /* VMS */ +#else /* VMS || OS2 || MSDOS */ static struct { @@ -1063,7 +1072,7 @@ struct redirect *rp; free(pipes[cur].command); return rval; } -#endif /* VMS */ +#endif /* VMS || OS2 || MSDOS */ #endif /* PIPES_SIMULATED */ @@ -1088,7 +1097,7 @@ NODE *tree; rp = redirect(tree->rnode, &redir_error); if (rp == NULL && redir_error) { /* failed redirect */ if (! do_unix) { - char *s = strerror(redir_error); + s = strerror(redir_error); unref(ERRNO_node->var_value); ERRNO_node->var_value = @@ -1103,7 +1112,7 @@ NODE *tree; errcode = 0; cnt = get_a_record(&s, iop, *RS, & errcode); if (! do_unix && errcode != 0) { - char *s = strerror(errcode); + s = strerror(errcode); unref(ERRNO_node->var_value); ERRNO_node->var_value = make_string(s, strlen(s)); @@ -1149,7 +1158,7 @@ NODE *tree; int pathopen (file) -char *file; +const char *file; { int fd = do_pathopen(file); @@ -1181,12 +1190,12 @@ char *file; static int do_pathopen (file) -char *file; +const char *file; { - static char *savepath = DEFPATH; /* defined in config.h */ + static const char *savepath = DEFPATH; /* defined in config.h */ static int first = 1; - char *awkpath, *cp; - char trypath[BUFSIZ]; + const char *awkpath; + char *cp, trypath[BUFSIZ]; int fd; if (STREQ(file, "-")) |