[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: require bug?
- From: Frederico Rodrigues Abraham <devotion97@...>
- Date: Thu, 25 Sep 2008 10:46:38 -0500
Hi all.
I was having this strange problem with my program.
An error happened in the code: require 'corr'
Error: error loading module 'corr' from file
'app/geresim/prerock/lua/corr': cannot read
app/geresim/prerock/lua/corr: Is a directory
This error does not happen in Windows but is happening in my Linux machine.
The problem is, the 'app/geresim/prerock/lua' directory contains both a
'corr' directory and a 'corr.lua' file.
In loadlib.c, 'require' uses this 'readable' function to search
package.path for existent lua files:
332 static int readable (const char *filename) {
333 FILE *f = fopen(filename, "r"); /* try to open file */
334 if (f == NULL) return 0; /* open failed */
335 fclose(f);
336 return 1;
337 }
The problem is, apparently fopen succeeds when trying to open a
directory but later on, when the file is actually fread from, this error
happens.
I changed 'readable' so that it will fail if reading from the file fails:
332 static int readable (const char *filename) {
333 int ret = 1;
334 FILE *f = fopen(filename, "r"); /* try to open file */
335 if (f == NULL) return 0; /* open failed */
336 if (fgetc(f) == EOF && ferror(f)) ret = 0; /* open succeeded but
read returns error */
337 fclose(f);
338 return ret;
339 }
Apparently this works as I expected.
Was this intended to be this way? Or is this a bug?
Regards,
-- Fred