[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gawk-stable] bug: fatal error when getline from directory
From: |
Paolo |
Subject: |
Re: [gawk-stable] bug: fatal error when getline from directory |
Date: |
Sat, 3 Jan 2009 23:34:04 +0100 |
User-agent: |
Mutt/1.3.28i |
On Sat, Jan 03, 2009 at 10:00:50PM +0200, Aharon Robbins wrote:
> Greetings. Re this:
and HNY everybody :)
...
> I have to decide what "the right thing" is here. Just to close the loop
...
> Different awks do different things when handed a directory. Brian
...
> $ for i in nawk mawk mksawk gawk
...
> In the same vein, each awk behaves differently when given a
> directory on the command line. BWK awk and mksawk (used in Solaris
...
> I will consult with the other awk authors before I decide what to do.
well, all such *awk incarnation do the wrong thing IMHO: I do expect an
error signal when an error does happen, and possibly to know why; just
ignoring the error condition is wrong, as well as aborting the script.
Behaviour should be something like eg open(2) in C, where you'd get rc=-1
and errno=EISDIR|EACCES|ENOENT|... and your program/script has then a
chance to handle the exception.
BTW, as mentioned in the original bugrep, gawk *should* already do like
above, according to info:
...
The `getline' command returns one if it finds a record and zero if
it encounters the end of the file. If there is some error in getting a
record, such as a file that cannot be opened, then `getline' returns
-1. In this case, `gawk' sets the variable `ERRNO' to a string
describing the error that occurred.
...
so the manual says the right thing, pity the code *does* the wrong one.
Indeed, gawk does do as the man says, but not always - eg when the file
has no read permissions:
$ gawk 'BEGIN{x=4; r=getline x < "/tmp/a"; print r " " x " ERRNO=" ERRNO}'
-1 4 ERRNO=Permission denied
so it just need to do the same in all other error conditions, and we'll be
all happy. I guess the fix is quite straightforward - lessee ...
#-------------
--- io.c 2009-01-03 23:28:14.000000000 +0100
+++ io.c 2009-01-03 23:25:21.000000000 +0100
@@ -1591,8 +1591,11 @@
if (openfd == INVALID_HANDLE)
openfd = open(name, flag, 0666);
if (openfd != INVALID_HANDLE) {
- if (os_isdir(openfd))
- fatal(_("file `%s' is a directory"), name);
+ if (os_isdir(openfd)) {
+ openfd = INVALID_HANDLE;
+ errno = EISDIR;
+ // fatal(_("file `%s' is a directory"), name);
+ }
}
/*
* At this point, fd could still be INVALID_HANDLE.
#-------------
test:
$ ./gawk 'BEGIN{x=4; r=getline x < "/tmp"; print r " " x " ERRNO=" ERRNO}'
-1 4 ERRNO=Is a directory
seems to work - but I really like more John Cowan's idea, awkish and
perlish :)
thanx
--
paolo
- [gawk-stable] bug: fatal error when getline from directory, Steffen Schuler, 2009/01/01
- Re: [gawk-stable] bug: fatal error when getline from directory, Aharon Robbins, 2009/01/03
- Re: [gawk-stable] bug: fatal error when getline from directory, John Cowan, 2009/01/03
- Re: [gawk-stable] bug: fatal error when getline from directory,
Paolo <=
- Re: [gawk-stable] bug: fatal error when getline from directory, Eric Blake, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Paolo, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Eric Blake, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Andreas Schwab, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Paolo, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Eric Blake, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Paolo, 2009/01/05
- Re: [gawk-stable] bug: fatal error when getline from directory, Eli Zaretskii, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Paolo, 2009/01/04
- Re: [gawk-stable] bug: fatal error when getline from directory, Andreas Schwab, 2009/01/04