Search code examples
linuxposixtmptemporary-files

set directory of tmpfile() on Linux


A program I use is failing when it uses tmpfile() for large files. The problem seems to be I don't have permission to create large files in /tmp, which this function uses by default. So is there a way, perhaps with an environmental variable, that I can make tmpfile() write to a different location?

Edit: the program in question is sox, which uses C.


Solution

  • You can use the environment variable TMPDIR to to tell tmpfile() where to create files:

    sh syntax:

    TMPDIR=/path/to/whatever; export TMPDIR
    

    csh syntax:

    setenv TMPDIR /path/to/whatever