Stdio.file_size reports wrong size for directories
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=4209
Reported by Leif Andersson, LTH Reglerteknik leif@control.lth.se
The documentation for Stdio.file_size states:
//! Give the size of a file. Size -1 indicates that the file either //! does not exist, or that it is not readable by you. Size -2 //! indicates that it is a directory, -3 that it is a symlink and -4 //! that it is a device. //!
The snapshot of 7.7, that I took a few days ago, however, does not give -2 for a directory, but rather the same size as reported by ls -l.
The test script, named prov.pike is:
//======== prov.pike =========================
int size;
string filename;
int main() {
filename = "prov.pike";
size = Stdio.file_size(filename);
write("%s size = %d\n", filename,size);
filename = "nisse.nisse";
size = Stdio.file_size(filename);
write("%s size = %d\n", filename,size);
filename = "pike";
size = Stdio.file_size(filename);
write("%s size = %d\n", filename,size);
}
// =========== end prov.pike ==============
============== Test results: =====================
ls -ld pike prov.pike nisse.nisse ls: nisse.nisse: No such file or directory drwxr-xr-x 3 leif dip 4096 12 jul 18.29 pike/ -rw-r--r-- 1 leif dip 369 20 jul 12.45 prov.pike
/opt/pike/7.7.25/bin/pike prov.pike prov.pike size = 369 nisse.nisse size = -1 pike size = 4096
============= Specifications: =============
head -1 /etc/issue Fedora Core release 5 (Bordeaux)
> uname -srv
Linux 2.6.17-1.2145_FC5smp #1 SMP Sat Jul 1 13:19:14 EDT 2006
> cat buildid.txt
Pike export stamp
time:1152866217
major:7
minor:7
build:25
year:2006
month:07
day:14
hour:08
minute:36
second:57
>
======== Other comments ================
Other versions of Pike, including the current stable version 7.6.86, give results according to the documentation. This version compiled on an FC4 gives the same erroneous result.