Re: an idea: "letter bombs"

Bennett Todd (bet@std.sbi.com)
Fri, 17 Dec 1993 13:55:07 -0500 (EST)

Guido.van.Rossum@cwi.nl writes:
>You can almost do this by catching IOError and os.error, except that
>the exception does not include the name of the offending file.

Ouch! This might be painful. How many different places does Python open and
close files? If there aren't too many, you could use a hack I found helpful
in a related context: allocate an array of getdtablesize(2) char pointers,
being prepared to resize the array if you get a larger FD back ---
getdtablesize(2) is permitted to change. Whenever you open a file, store the
filename in the array slot subscripted by the file descriptor. Whenever you
close a file, delete (and free the string storage space for) that FD. Then
you've got a map for translating FDs to filenames. I actually used the array
through a subroutine, so I could call filename(fd) and get back the filename
if it was known; stdin, stdout, or stderr for fd#0, fd#1, and fd#2
respectively if no other name was stored, and a string "fd#NNN" for any
other unknown file descriptor. This turned out to work beautifully for error
messages.

-Bennett
bet@sbi.com