Using open Open will follow symlinks and dangling symlinks. It's tempting to do stat calls first to be sure you're not tricked, but that's still a race condition. If you're sure the file should not exist before you create it, use the O_EXCL flag to open. fd = open( FILENAME, O_CREAT | O_RDWR | O_EXCL, 0666 ); or for Perl folks use Fcntl; sysopen( HANDLE, $filename, O_CREAT | O_RDWR | O_EXCL ) or die; # mode defaults to 0666 # perldoc perlopentut for more wonders