If you want your editor to be versatile and handle files originating from various systems in a sensible way, you should accept all 3 possibilities for the line ending sequence: a single LF byte for unix systems, including linux and OS/X, a single CR byte for files created on the older macOS versions, and the sequence CR+LF for files produced on Microsoft Windows, MS/DOS and the original CP/M system.
You could autodetect the end-of-line flavor by scanning the beginning of the file: if you find CR+LF sequences, you have a windows file, if you have CR bytes not followed by LF, is an oldmac file, if you have LF bytes, it is a unix file, if none of the above are present, it is either a binary file or a single line text file without a line ending. For these, use the default for the current execution platform.
Whether you preserve the line ending flavor for modifications or you convert the line ending sequences to the local flavor is a design decision. In Quick Emacs, I chose to preserve the line ending flavor and let the user perform the conversion on demand with specific commands.
In any case, you should open the file in binary mode for both reading and writing and handle the line endings explicitly in your program.