[#2338] Add method to find the temporary directory

The code is essentially borrowed from clar/sandbox.h:find_tmp_path,
mainly removing the CLAR_TMP as a valid environment variable.