Reply
Thread Tools
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#1
Hi,
I'm trying to read/write from a file in the scratchbox (maemo5sdk) but just being unsuccessful. So, I'm wondering is there a different way to do such in maemo for now I'm trying with FILE *fptr = fopen("filename", "mode"); Its just returning me an error which I've set up if the fptr is NULL. This is for a home widget which will read the file to initialize its value with the file's contents and save the values to the same file when new settings are applied. Any help/suggestion would be greatly appreciated. Thank you.
 

The Following User Says Thank You to jaeezzy For This Useful Post:
Posts: 452 | Thanked: 522 times | Joined on Nov 2007
#2
Originally Posted by jaeezzy View Post
Hi,
I'm trying to read/write from a file in the scratchbox (maemo5sdk) but just being unsuccessful. So, I'm wondering is there a different way to do such in maemo for now I'm trying with FILE *fptr = fopen("filename", "mode"); Its just returning me an error which I've set up if the fptr is NULL. This is for a home widget which will read the file to initialize its value with the file's contents and save the values to the same file when new settings are applied. Any help/suggestion would be greatly appreciated. Thank you.

A couple things;
1. How did you create the file (inside or outside of scratchbox)
2. Are you sure of the path . If you do "~/MyDocs/" this will be your MyDocs folder.
3. What is the mode you are picking?

Nathan
 
Posts: 25 | Thanked: 12 times | Joined on Mar 2008 @ Warsaw, Poland
#3
What file open mode are you trying? Does the file exist? What is "errno" set to after you do fopen()?
From the `man 3 fopen'
RETURN VALUE
Upon successful completion fopen(), fdopen() and freopen() return a FILE pointer. Oth‐
erwise, NULL is returned and errno is set to indicate the error.
Oh, and you should also be able to try "strace ./path/to/your/binary", which should already tell what fopen() returns (with a meaningful error name, like EPERM or whatever is the error you get).
Once you get the error "name" you can look-up what it means in `man 3 errno'

Last edited by arachnist; 2009-10-19 at 03:16. Reason: Forgot about strace
 

The Following User Says Thank You to arachnist For This Useful Post:
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#4
Thanks Nathan for the reply. After you said, I created the file inside scratchbox and before as it was in the same working directory, I wan't giving the full address, now I did and it is reading but the problem now is, I've contents in the file as follows:

folder: /home/user/somedir
sthelse: somevalue

So, I decided to use fscanf(); and check if it reaches the end with !feof(fPtr); but it doesn't seem to be doing what it's suppose to do as I put I g_print() statement and it keeps printing that. Btw, I created the file with vim inside scratchbox.
 
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#5
Thanks guys its finally sorted. I'm really freaked out- first it doesn't work at all and later it is all working. It's all good, just that in-between there's lot of head banging. Thanks..

Last edited by jaeezzy; 2009-10-19 at 08:36.
 
Reply


 
Forum Jump


All times are GMT. The time now is 20:37.