| Bezoar 2007-08-31, 5:44 am |
| On Aug 30, 4:53 pm, daneyu...@gmail.com wrote:
> If I've lost track of a filename that a channel was opened for, is
> there a way to get the filename from just the channel name?
>
> In other words, after doing the following:
>
> set file_handle [open $filename r]
>
> can I then use $file_handle to determine $filename?
>
> -Daniel
just override your open call to creat an array of file descriptors
and their associated filenamss, or what not. Overload close to remove
from the global array
global fd2filename
array set { stdin stdin stdout stdout stderr stderr }
rename open Open
proc open { args } {
global fd2filename
set fname { lindex $args 0 ]
set fd [ eval Open $args ]
set fd2filename($fd) $filename
return $fd;
}
..... do same thing for close except you remove
the array index from the global array and when
you want to find out what the filename is you
merely
set fd [ open /tmp/log.file "r" 0660 ]
puts "filename for fd is $fd2filename($fd)"
I probably forgot something as I did not test this
out but it should work.
Carl
|