in reply to How to chomp the last new line character from the file

  1. Verify that the file exists and that it is writable by you.
  2. Seek to the end of the file, obtaining its length in bytes.   Exit if zero.
  3. Seek one byte back from where you are.   Read that byte.   Exit if not a newline.   (Assuming no double-bye character-set nonsense; otherwise, you must back up one character.)
  4. Truncate the file at length - 1.