open() does not appear to work with newlib

7 posts / 0 new
Last post
apcameron
apcameron's picture
Offline
Joined: 29 Jun 2010
Posts:
open() does not appear to work with newlib

When I run the program below the open () statement always returns -1 even if the file exists.
Am I doing something wrong?

#include
#include
#include
#include
#include

int rc;
const char *dbname = "/temp/my_db.sql3";

int MAMain() {
rc = open( dbname, O_WRONLY );
fprintf(stderr, "rc= %-3d %s \n", rc, dbname);
close(rc);
FREEZE;
return 0;
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Fredrik Eldh
Fredrik's picture
Offline
Mobile Sorcerer
Joined: 16 Feb 2009
Posts:

Are you running it in the emulator? In that case, the filesystem as exposed to MoSync programs is chrooted in the subdirectory Output/filesystem, of your project directory.

apcameron
apcameron's picture
Offline
Joined: 29 Jun 2010
Posts:

Yes, I am running it in the Mosync Emulator.

I will try it tonight and let you know if that solves my problem but I am not sure it will as

rc = open( dbname, O_WRONLY | O_CREAT);

was also failing.

Fredrik Eldh
Fredrik's picture
Offline
Mobile Sorcerer
Joined: 16 Feb 2009
Posts:

I'm assuming you use newlib. Which version of MoSync are you using?

I introduced a bug to open() in r1644. If you're using that version or a later one, I'm surprised your program doesn't crash. Smile

Anyway, after fixing the bug, I tried to run your test program (with one change: const char *dbname = "/my_db.sql3"; // removed "temp/"), and it worked fine, printing "rc= 4 /my_db.sql3".

The fix is in r1652.

apcameron
apcameron's picture
Offline
Joined: 29 Jun 2010
Posts:

Thank you.
I was using 1650.
I will test it tonight.

apcameron
apcameron's picture
Offline
Joined: 29 Jun 2010
Posts:

Thanks,

That fixed the open problem.

apcameron
apcameron's picture
Offline
Joined: 29 Jun 2010
Posts:

Does this work on Nokia Devices.

A Similar Open statement which works on the Emulator seems to fail on a Nokia 5230 Device.

A File name of "test.db" works but something like "/test.db" fails.
Then after I create the file I cannot seem to find it on my device.