Overwrite an already existing symlink

This commit is contained in:
James R 2019-12-24 01:55:47 -08:00
parent 908266f583
commit 5d0c19af37

View file

@ -142,6 +142,7 @@ int main(int argc, char **argv)
const char *reldir; const char *reldir;
int left; int left;
boolean fileabs; boolean fileabs;
const char *link;
logdir = D_Home(); logdir = D_Home();
@ -201,11 +202,12 @@ int main(int argc, char **argv)
#ifdef __unix__ #ifdef __unix__
logstream = fopen(logfilename, "w"); logstream = fopen(logfilename, "w");
#ifdef DEFAULTDIR #ifdef DEFAULTDIR
if (symlink(logfilename, link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir);
va("%s/"DEFAULTDIR"/latest-log.txt", logdir)) == -1)
#else #else
if (symlink(logfilename, va("%s/latest-log.txt", logdir)) == -1) link = va("%s/latest-log.txt", logdir);
#endif/*DEFAULTDIR*/ #endif/*DEFAULTDIR*/
unlink(link);
if (symlink(logfilename, link) == -1)
{ {
I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno)); I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno));
} }