Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Write to filesystem from a program: (2 Items)
   
Write to filesystem from a program  
Hi All,
I am trying to create a new file and write to a new file but when i try to open the new file it is crashing the program.
I am working in Neutrino 6.6 and sabrelite board with bsp-freescale-mx6q-sabrelite-SDP6.6 BSP.
    I have created a partition in the SD Card with the command fdisk of DOS filesystem type.

My sample code.The mountret is 0 in the below call
    FILE *fp;
    int mountret=mount("/dev/hd0t1","/usr",_MOUNT_REMOUNT,"dos",'\0',-1);
    fd=fopen("/usr/test/data.txt",'a');
    if(fd==NULL)
    {
       printf("fopen error");
    }
    datbuf.chardata='a';
        datbuf.floatdata=1.152;
        datbuf.intdata=20;

        fwrite((const void*)&datbuf,sizeof(datbuf),1,fd);
    
        fclose(fd);

Thanks in advance for your replies,
With regards,
Praveen Kumar
RE: Write to filesystem from a program  
Your second argument to fopen is a char, but it should be a pointer to string (const char *).  I'm surprise you didn`t 
get a compiler warning.

Furthermore your code does check for fd == NULL but  aside printing an error message, the code will end up using it, 
most probably ending in a crash.

-----Message d'origine-----
De : Praveen Kumar [mailto:community-noreply@qnx.com] 
Envoyé : 14 septembre 2014 04:52
À : ostech-core_os
Objet : Write to filesystem from a program

Hi All,
I am trying to create a new file and write to a new file but when i try to open the new file it is crashing the program.
I am working in Neutrino 6.6 and sabrelite board with bsp-freescale-mx6q-sabrelite-SDP6.6 BSP.
    I have created a partition in the SD Card with the command fdisk of DOS filesystem type.

My sample code.The mountret is 0 in the below call
    FILE *fp;
    int mountret=mount("/dev/hd0t1","/usr",_MOUNT_REMOUNT,"dos",'\0',-1);
    fd=fopen("/usr/test/data.txt",'a');
    if(fd==NULL)
    {
       printf("fopen error");
    }
    datbuf.chardata='a';
        datbuf.floatdata=1.152;
        datbuf.intdata=20;

        fwrite((const void*)&datbuf,sizeof(datbuf),1,fd);
    
        fclose(fd);

Thanks in advance for your replies,
With regards,
Praveen Kumar



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post111706
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com