On linux, is it normal that there is no null character at the end of the file

in linux, is it normal that there is no null character at the end of the file?

I made an empty file and opened it with write az mouse pad.

save it.

when I open the file with a hex editor, there is no null character, but there is 0a.

what null character do i have to end the file?

when I write a file with a system call.

is it 0a? or 0?

thanks

+4
source share
4 answers

The file system writes the number of bytes in the file, and all bytes can have any value - no specific character / byte value is a reserved inquiry value, meaning the end of the file. That way you can have NUL anywhere in the file, but you don't have to mark it.

Each line of a text file really needs to be completed with a line feed, ASCII 10 dec, 0A hex (on Windows, this will be an ASCII 13 dec carriage return followed by a line). If you create an empty ala echo > filename , it will have one line output, but only because by default the echo prints an empty line. If you used touch filename , it would be completely empty.

When you cat > filename and enter things into the terminal / console window, you end up using Control-D to run the end of file condition (for Linux / Control-Z in DOS), but this character is not stored in the file itself.

+5
source

Unix usually has no null character at the end of files. An empty text file has zero bytes. One empty line will have the character 0x0A (LF, linefeed). Unix text files have single LF line endings.

+7
source

0a is a new line, as well as control-J or \n . Text files usually do not end with a null character in Unix.

+2
source

It depends on who implemented the file format.

-1
source

Source: https://habr.com/ru/post/1345483/


All Articles