Use temporary directories named conftestdir{,2}, not foo and bar. Create conftestdir/ in the script, not in the C code. Remove directories in the script, not in the C code.