I've checked the Tcl man pages and the tcl-usage F.A.Q., but none of
them mentions that the result produced by {file exists ""} is
OS-dependent, i.e. that the file command, with its various options,
doesn't treat the empty file name in the same way on various operating
systems.
So, for example on a SunOS 5.4 sun4m sparc, tclsh7.5 says:
% file exists ""
0
while on a ULTRIX 4.3 RISC, tclsh7.4 says:
% file exists ""
1
As far as I understand the source code, versions 7.4 and 7.5 both
process the command in the same way, i.e. by invoking the access()
system call which doesn't produce the same result on various Unix
systems (what about other platforms?) if the specified file name is an
empty string.
The problem also exists in some other variations of the file command
-- try to execute the example tcl code at the end of this message to
see which commands produce what results (or errors) on your system.
I think it would be nice that the empty file name in these commands is
treated in the same way on all operating system. This would be an
improvement, wouldn't it?
For example, I would expect that {file exists ""} returns false (0) as
I don't know of an OS which allows empty file names. To achieve this
functionality, some trivial changes are needed in the C source code,
for example, something like the following:
if (! *fileName) {
/* set the result to a sane value or generate an error */
}
Also, I would put a word about the issue in the man page.
Any comments?
v
-- rpr. : Robert B. Premuz * Email: rpr...@public.srce.hr
http://public.srce.hr/~rpremuz/ * Voice at home: +385 (0)1 687564
----------------------------------------------------------------------
#!/usr/local/bin/tclsh
set tclCommands {
{file atime ""}
{file executable ""}
{file exists ""}
{file isdirectory ""}
{file isfile ""}
{file lstat "" fileLStat}
{file mtime ""}
{file owned ""}
{file readable ""}
{file readlink ""}
{file size ""}
{file stat "" fileStat}
{file type ""}
{file writable ""}
}
foreach command $tclCommands {
puts "Executing {$command}"
if [catch {puts [eval $command]} err] {
puts $err
}
}
exit
According to Robert Premuz <rpr...@srce.hr>:
:Hello,
:
:I've checked the Tcl man pages and the tcl-usage F.A.Q., but none of
:them mentions that the result produced by {file exists ""} is
:OS-dependent, i.e. that the file command, with its various options,
:doesn't treat the empty file name in the same way on various operating
:systems.
Yep - that's probably because trying to refer to a null string as
a pathname was at least on pre-posix an undefined action, resulting in
just the differences mentioned. Seems like it might be useful for
you to send this info along to the Tcl FAQ maintain and ask that
it be documented - though frankly, it isn't directly Tcl-specific problem
(though, to counter balance this, Tcl _could_ standardize its behavior
here by _checking_ for "" and always doing the same thing before
going to the OS).
But it comes back to the problem discussed in another thread -
should, somewhere, unexpected behavior be documented.
--
:s Larry W. Virden INET: lvi...@cas.org
:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.