chdir("~/") doesn't seem to work. Am I expected to look at the string and substitute tilde by hand, or is there some better way?
chdir("~/")
POSIX provides wordexp(3) to perform shell-like expansion, including tilde expansion.
wordexp(3)