- my $fh = IO::File->new($dir, $mode | O_TMPFILE, $perm)
- or die "failed to create tempfile: $!\n";
+ my $fh = IO::File->new($dir, $mode | O_TMPFILE, $perm);
+ if (!$fh && $! == EOPNOTSUPP) {
+ $dir = '/tmp' if !defined($opts{dir});
+ $dir .= "/.tmpfile.$$";
+ $fh = IO::File->new($dir, $mode | O_CREAT | O_EXCL, $perm);
+ unlink($dir) if $fh;
+ }
+ die "failed to create tempfile: $!\n" if !$fh;