<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><span><br></span></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; "><div style="font-family: 'times new roman', 'new york', times, serif; "><font size="2" face="Arial" style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><hr size="1"><b><span style="font-weight:bold;">От:</span></b> Joel Sherrill <joel.sherrill@oarcorp.com><br><b><span style="font-weight: bold;">Кому:</span></b> Oleg Moroz <oleg_moroz@yahoo.com>; "rtems-users@rtems.org" <rtems-users@rtems.org><br><b><span style="font-weight: bold;">Отправлено:</span></b> четверг, 26 май 2011
 21:57<br><b><span style="font-weight: bold;">Тема:</span></b> Re: r+b filemode<br></font><br><font class="Apple-style-span" size="3">Which filesystem?</font><br><br><font class="Apple-style-span" size="3">Do you have a complete small test case?</font><br><br><font class="Apple-style-span" size="3">Someone else will likely have other ideas.  I am on travel and just wanted to ask the obviuous questions.</font><br><br><font class="Apple-style-span" size="3">--joel</font><br><br><font class="Apple-style-span" size="3">Oleg Moroz <</font><a ymailto="mailto:oleg_moroz@yahoo.com" href="mailto:oleg_moroz@yahoo.com" style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">oleg_moroz@yahoo.com</a><font class="Apple-style-span" size="3">> wrote:</font><br><br><font class="Apple-style-span" size="3">>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:</font><br><font class="Apple-style-span" size="3">></font><br><font class="Apple-style-span" size="3">>///</font><br><font class="Apple-style-span" size="3">>fseek(file,0,SEEK_END);</font><br><font class="Apple-style-span" size="3">>int i = ftell(file);</font><br><font class="Apple-style-span" size="3">>///</font><br><font class="Apple-style-span" size="3">></font><br><font class="Apple-style-span" size="3">></font><br><font class="Apple-style-span" size="3">></font><br><font class="Apple-style-span" size="3">>after this i=0</font><br><font class="Apple-style-span" size="3">></font><br><font class="Apple-style-span" size="3">>but when i'm opening file with "rb" mode - i=512. how i can use "r+b" mode?</font></div><div class="yui_3_2_0_2_130647221712157"><font class="Apple-style-span" size="3"></font><br><div class="yui_3_2_0_2_130647221712157">int
 create_ring_buffer_file(char *filename)</div><div class="yui_3_2_0_2_130647221712157">{</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">      </span>FILE* outfile=fopen(filename,"wb");</div><div class="yui_3_2_0_2_130647221712157"><br></div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">   </span>if (outfile==NULL) return -1;</div><div class="yui_3_2_0_2_130647221712157"><br></div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">   </span>char *block=(char *)malloc(512);</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">       </span>memset(block,0,512);</div><div class="yui_3_2_0_2_130647221712157"><br></div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">    </span>fwrite(block,512,1,outfile);</div><div
 class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">       </span>free(block);</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">   </span>fclose(outfile);</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">       </span>outfile=fopen(filename,"r+b");</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">       </span>fseek(outfile,0,2);</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">    </span>int i = ftell(outfile); //i=0</div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">  </span>fclose(outfile);</div><div class="yui_3_2_0_2_130647221712157"><br></div><div class="yui_3_2_0_2_130647221712157"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div class="yui_3_2_0_2_130647221712157"
 style="font-family: 'times new roman', 'new york', times, serif; "><span class="Apple-tab-span" style="white-space: pre; ">     </span>outfile=fopen(filename,"rb");</div><div class="yui_3_2_0_2_130647221712157" style="font-family: 'times new roman', 'new york', times, serif; "><span class="Apple-tab-span" style="white-space: pre; ">        </span>fseek(outfile,0,2);</div><div class="yui_3_2_0_2_130647221712157" style="font-family: 'times new roman', 'new york', times, serif; "><span class="Apple-tab-span" style="white-space: pre; ">    </span>int i = ftell(outfile); //i=512</div><div class="yui_3_2_0_2_130647221712157" style="font-family: 'times new roman', 'new york', times, serif; "><span class="Apple-tab-span" style="white-space: pre; ">        </span>fclose(outfile);</div></div><div class="yui_3_2_0_2_130647221712157"><span class="Apple-tab-span" style="white-space:pre">   </span>return 0;</div><div
 class="yui_3_2_0_2_130647221712157">}</div><br></div></div></div></body></html>