in linux, is it normal that there is no null character at the end of file?
I made a empty file and open with mouse pad write az.
save it.
when I open the file up with hex editor, there is no null character but 0a is there.
what null character should I put the end of file?
when I write the file with system call.
is it 0a? or 0?
thanks
The filesystem records the number of bytes in a file, and all the bytes are free to have any value - no particular character/byte value is a reserved sentinel value meaning end-of-file. So, you can have a NUL anywhere in the file, but don't need one to mark the end.
Each line in a text file should indeed be terminated with a linefeed, ASCII 10 dec, 0A hex (on Windows it'd be a carriage return ASCII 13 dec followed by a linefeed). If you create an empty file ala echo > filename
it will have one linefeed, but only because echo prints an empty line by default. If you instead used touch filename
it would be completely empty.
When you cat > filename
and type things into your terminal/console window, you eventually use Control-D to trigger an end-of-file condition (for Linux / Control-Z in DOS), but that character is not stored in the file itself.