X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f02de746f64f0879e1d8dc754293a121b686646b..a1dcc0bd9e1ffd90ef88cd19f8ff8197f541c8a8:/sbr/m_mktemp.c diff --git a/sbr/m_mktemp.c b/sbr/m_mktemp.c index 17cf7458..6bfa705f 100644 --- a/sbr/m_mktemp.c +++ b/sbr/m_mktemp.c @@ -170,7 +170,7 @@ m_mktemps( fd = mkstemps(tmpfil, (int) strlen(suffix)); #else /* ! HAVE_MKSTEMPS */ - /* Solaris 10, e.g. */ + /* NetBSD, Solaris 10 */ if (pfx_in == NULL) { tmpfil = concat(get_temp_dir(), "/nmhXXXXXX", NULL); @@ -181,31 +181,15 @@ m_mktemps( fd = mkstemp(tmpfil); { char *oldfilename = tmpfil; - tmpfil = concat(oldfilename, suffix, NULL); - /* link(2) requires that the new path not exist. And if we - have to resort to rename(2), at least try to remove a file - that would be in the way. */ - if (unlink(tmpfil) != 0 && errno != ENOENT) { - advise("unlink", "Failed to unlink \"%s\"", tmpfil); + if (rename(oldfilename, tmpfil) != 0) { (void) unlink(oldfilename); free(oldfilename); free(tmpfil); return NULL; } - /* link() doesn't always work, such as on Windows FAT - filesystems. If it fails, try rename(). */ - if (link(oldfilename, tmpfil) != 0 && - rename(oldfilename, tmpfil) != 0) { - (void) unlink(oldfilename); - free(oldfilename); - free(tmpfil); - return NULL; - } - - (void) unlink(oldfilename); free(oldfilename); } #endif /* ! HAVE_MKSTEMPS */ @@ -371,13 +355,13 @@ remove_registered_files(int sig) { exit(1); } else { + remove_registered_files_atexit(); + act.sa_handler = SIG_DFL; (void) sigemptyset(&act.sa_mask); act.sa_flags = 0; (void) sigaction(sig, &act, 0); - remove_registered_files_atexit(); - (void) raise(sig); } }