0

I'm using FlasCC+Swig to call my C function in Adobe Air application.

The C function:

int file_exists(const char filename[]) {
    struct stat stbuf;
    if (stat(filename, &stbuf) == -1) {
        return (0);
    }
    return (1);
}

In my normal command line (of course, first compile a main.cpp), if I supply "/tmp/test.txt" (the file exists), the function file_exists returns 1, which is expected.

However, after I use FlasCC+Swig to compile this C function file_exists, and generate a swc library, and add this library to my Adobe Air application, and run it, it always returns 0, which is incorrect.

I checked the errno, it's value is ENOENT (2):

A component of path does not name an existing file or path is an empty string.

http://pubs.opengroup.org/onlinepubs/7908799/xsh/stat.html

Can you give me some idea?

BTW, in my Adobe Air application:

var file:File = File.applicationDirectory.resolvePath(path);
trace(file.exists); // returns true

So the Adobe Air DOES have access to the local file system.

Peter Lee
  • 12,931
  • 11
  • 73
  • 100
  • 1
    Most likely, the process is in a jail of some kind and doesn't have access to the system's `/tmp` directory. – David Schwartz Feb 23 '14 at 03:21
  • I suspect Adobe Air runs in a sandbox like that. – Barmar Feb 23 '14 at 03:22
  • It seems the Adobe Air application DOES have access to the local file system. What if I put my files in some specific directories? (what kind of directories should I put, so that my C function `file_exist` will be able to detect it?) – Peter Lee Feb 23 '14 at 03:34
  • @DavidSchwartz and Barmar, you guys are right, see my own answer below. – Peter Lee Feb 25 '14 at 17:18

1 Answers1

0

It turns out that the low level c code won't be able to see the REAL local file system. We need to use the Adobe Virtual File System.

CModule.vfs.addDirectory("/MyPath/");
CModule.vfs.addFile("/MyPath/MyFile.txt", data);

After we set up the above VFS, our C file reading function will be able to see the file /MyPath/MyFile.txt.

Peter Lee
  • 12,931
  • 11
  • 73
  • 100