Resolve the home directory
Note that the "~" notation (used on Unix to indicate the user's home directory) is not resolved into a valid path by open/4 ... which is normal as it is actually a shell convention: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html (not sure it is even POSIX).
The C function to examine the user database and get home directories (among others) of some user X is
In SWI-Prolog, expand_file_name/2 can be used:
?- expand_file_name("~", Home). Home = ['/home/paquette']. ?- expand_file_name("~root", Home). Home = ['/root'].
What about the encoding of a text file?
According to the text above:
The default encoding for type text is derived from the Prolog flag
For binary streams the default encoding is
For details on encoding issues, see section encoding.
Under Prolog flag
encoding, we read:
Default encoding used for opening files in text mode. The initial value is deduced from the environment.
So I guess, the environment variable
LANG is the one which determines the encoding which is used by default.
For portability, never assume a default encoding. In the 21st century, using
utf8 is best.