'fopen' successfully opens directories

Sergei Steshenko sergstesh at yahoo.com
Wed Apr 23 11:08:57 CDT 2008


--- "John W. Eaton" <jwe at bevo.che.wisc.edu> wrote:

> On 23-Apr-2008, Sergei Steshenko wrote:
> 
> | Hello,
> | 
> | please see this:
> | 
> | "
> | GNU Octave, version 3.0.1b
> | [snip]
> | octave:1> fid = fopen("/tmp", "r")
> | fid =  3
> | octave:2> fread(fid, inf, "double")
> | ans = [](0x1)
> | "
> | 
> | - I would expect failure, i.e. negative 'fid', from 'fopen' in such a case.
> 
> What does the following C program do on your system?
> 
>   #include <errno.h>
>   #include <stdio.h>
> 
>   int
>   main (void)
>   {
>     FILE *fid = fopen ("/tmp", "r");
> 
>     if (fid)
>       printf ("OK\n");
> 
>     printf ("errno: %d\n", errno);
> 
>     return 0;
>   }
> 
> 
> I'm not convinced that Octave should do anything different from this.
> 
> jwe
> 

Let's suppose the program works.

If so, what useful can be done with 'fid' ?

My point is that if I open a file, I can iterate over the FID using 'read' function
and thus extracting item by item (minimally byte by byte) from the file.

Likewise, if I open a directory using 'opendir', I can iterate over the directory handle
using 'readdir' and thus extracting item by item (file or directory names) from the directory.

I discovered this problem incidentally, not with /tmp, but rather forgetting to copy-paste
part of path, i.e. I had /foo/bar instead of full /foo/bar/doo/dah/file.

At least a friendly warning ...

Thanks,
  Sergei.


Applications From Scratch: http://appsfromscratch.berlios.de/


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


More information about the Bug-octave mailing list