From 161f3ef74b2bbf7cf42a6868f42f5bdb1c442dda Mon Sep 17 00:00:00 2001 From: Goran Jelic-Cizmek Date: Sat, 14 Dec 2024 22:19:39 +0100 Subject: [PATCH] Replace `cleanup` and Win32 script with std::filesystem --- share/lib/cleanup | 8 -------- src/oc/hoc.cpp | 18 +++++------------- src/oc/mswinprt.cpp | 13 ------------- 3 files changed, 5 insertions(+), 34 deletions(-) delete mode 100755 share/lib/cleanup diff --git a/share/lib/cleanup b/share/lib/cleanup deleted file mode 100755 index 5ac223906d..0000000000 --- a/share/lib/cleanup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -if [ $TEMP ] ; then - tmpdir=$TEMP -else - tmpdir="/tmp" -fi -rm -f $tmpdir/oc"$1".hl diff --git a/src/oc/hoc.cpp b/src/oc/hoc.cpp index 7d0c16932f..0a2502b503 100644 --- a/src/oc/hoc.cpp +++ b/src/oc/hoc.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -169,9 +170,6 @@ void set_intset() { hoc_intset++; } #endif -#ifdef WIN32 -extern void hoc_win32_cleanup(); -#endif static int follow(int expect, int ifyes, int ifno); /* look ahead for >=, etc. */ static int Getc(NrnFILEWrap* fp); @@ -960,16 +958,10 @@ void hoc_final_exit(void) { rl_deprep_terminal(); #endif ivoc_cleanup(); -#ifdef WIN32 - hoc_win32_cleanup(); -#else - std::string cmd{neuron_home}; - cmd += "/lib/cleanup "; - cmd += std::to_string(hoc_pid()); - if (system(cmd.c_str())) { // fix warning: ignoring return value - return; - } -#endif + auto tmp_dir = std::getenv("TEMP"); + auto path = std::filesystem::path(tmp_dir ? tmp_dir : "/tmp") / "oc" / + std::to_string(hoc_pid()) / ".hl"; + std::filesystem::remove(path); } void hoc_quit(void) { diff --git a/src/oc/mswinprt.cpp b/src/oc/mswinprt.cpp index 3dfa805a3c..29ae6ec491 100644 --- a/src/oc/mswinprt.cpp +++ b/src/oc/mswinprt.cpp @@ -121,19 +121,6 @@ char* hoc_back2forward(char* s) { void ivoc_win32_cleanup(); #endif -void hoc_win32_cleanup() { - char buf[256]; - char* path; -#if HAVE_IV - ivoc_win32_cleanup(); -#endif - path = getenv("TEMP"); - if (path) { - Sprintf(buf, "%s/oc%d.hl", path, getpid()); - unlink(buf); - // DebugMessage("unlinked %s\n", buf); - } -} void hoc_win_exec(void) { int i;