Отв.: r+b filemode

Chris Johns chrisj at rtems.org
Fri May 27 07:38:14 UTC 2011


On 27/05/11 3:00 PM, Oleg Moroz wrote:
>
>
> ------------------------------------------------------------------------
> *От:* Joel Sherrill <joel.sherrill at oarcorp.com>
> *Кому:* Oleg Moroz <oleg_moroz at yahoo.com>; "rtems-users at rtems.org"
> <rtems-users at rtems.org>
> *Отправлено:* четверг, 26 май 2011 21:57
> *Тема:* Re: r+b filemode
>
> Which filesystem?
>
> Do you have a complete small test case?
>
> Someone else will likely have other ideas. I am on travel and just
> wanted to ask the obviuous questions.
>
> --joel
>
> Oleg Moroz <oleg_moroz at yahoo.com <mailto:oleg_moroz at yahoo.com>> wrote:
>
>  >Hello everyone, i have a trouble with opening file. i have opened the
> file with "wb" mode. Write to it 512 bytes. close it. after this open it
> with "r+b" mode. then trying:
>  >
>  >///
>  >fseek(file,0,SEEK_END);
>  >int i = ftell(file);
>  >///
>  >
>  >
>  >
>  >after this i=0
>  >
>  >but when i'm opening file with "rb" mode - i=512. how i can use "r+b"
> mode?
>
> int create_ring_buffer_file(char *filename)
> {
> FILE* outfile=fopen(filename,"wb");
>
> if (outfile==NULL) return -1;
>
> char *block=(char *)malloc(512);
> memset(block,0,512);
>
> fwrite(block,512,1,outfile);
> free(block);
> fclose(outfile);
> outfile=fopen(filename,"r+b");
> fseek(outfile,0,2);
> int i = ftell(outfile); //i=0
> fclose(outfile);
>
> outfile=fopen(filename,"rb");
> fseek(outfile,0,2);
> int i = ftell(outfile); //i=512
> fclose(outfile);
> return 0;
> }
>

Which file system are you using ?

Chris



More information about the users mailing list