ftruncate php csv阻止LF被删除

i write an array to csv file using fputcsv in php . i know that fputcsv writes a empty line as the last out put so my csv looks like

  1. apples
  2. orranges
  3. pear
  4. empty last line

What i did to remove the last empty line was use the below code and it works it writes a csv without the last empty line.

    $stat = fstat($handle);
    ftruncate($handle, $stat['size']-1);

My problem is that it delets the LF code and what than means on the next time i append to my csv a new value just gets appended to the same line as line 3 in stead of next line because the LF is missing ...

  1. apples LF
  2. orranges LF
  3. pear

anyone know how to fix the above ?