Отв.: r+b filemode
Oleg Moroz
oleg_moroz at yahoo.com
Fri May 27 05:00:19 UTC 2011
________________________________
От: 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> 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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20110527/822b2cf3/attachment-0001.html>
More information about the users
mailing list