What is a text file according to POSIX?

Tags: posix,

Added: 2024-12-05T00:00

What is a text file according to POSIX?

If you use Linux, you'll probably have heard of POSIX, as Linux is a mostly POSIX-compliant operating system.

Recently, I learnt something that surprised me - what the POSIX specification defines a text file as.

According to POSIX, a text file is defined as
A file that contains characters organized into zero or more lines. The lines do not contain NUL characters and none can exceed {LINE_MAX} bytes in length, including the character. Although POSIX.1-2024 does not distinguish between text files and binary files (see the ISO C standard), many utilities only produce predictable or meaningful output when operating on text files. The standard utilities that have such restrictions always specify "text files" in their STDIN or INPUT FILES sections.

And a line is defined as
A sequence of zero or more non-<newline> characters plus a terminating <newline> character.


So if your text file doesn't end with a new line, it's not a text file according to POSIX.

IntelliJ has an option for this:
File → Settings → Editor → General → Ensure every saved file ends with a line break

Posted by Calum on 2024-12-05T00:00 under: posix,
Add a comment

Your IP:
Please enter 7463366 here: