diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index 65044b5e801eeeaf8665d35c46449f5ecf216e6a..52bdc158e4fb41d347c8a3e1300f544b7b1bc3a4 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -448,18 +448,14 @@ initHeapProfiling(void) stem = stgMallocBytes(strlen(RtsFlags.CcFlags.outputFileNameStem) + 1, "initHeapProfiling"); strcpy(stem, RtsFlags.CcFlags.outputFileNameStem); } else { - stem = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling"); strcpy(stem, prog_name); + + // Drop the platform's executable suffix if there is one #if defined(mingw32_HOST_OS) - // on Windows, drop the .exe suffix if there is one - { - char *suff; - suff = strrchr(stem,'.'); - if (suff != NULL && !strcmp(suff,".exe")) { - *suff = '\0'; - } - } + dropExtension(stem, ".exe"); +#elif defined(wasm32_HOST_ARCH) + dropExtension(stem, ".wasm"); #endif } diff --git a/rts/Profiling.c b/rts/Profiling.c index 2ba985434b165e7f45f4f53d266d65d2af92160a..af629eb7421d43a56c33de1522d2ec383abc3849 100644 --- a/rts/Profiling.c +++ b/rts/Profiling.c @@ -245,19 +245,14 @@ initProfilingLogFile(void) if (RtsFlags.CcFlags.outputFileNameStem) { stem = RtsFlags.CcFlags.outputFileNameStem; } else { - char *prog; - - prog = arenaAlloc(prof_arena, strlen(prog_name) + 1); + char *prog = arenaAlloc(prof_arena, strlen(prog_name) + 1); strcpy(prog, prog_name); + + // Drop the platform's executable suffix if there is one #if defined(mingw32_HOST_OS) - // on Windows, drop the .exe suffix if there is one - { - char *suff; - suff = strrchr(prog,'.'); - if (suff != NULL && !strcmp(suff,".exe")) { - *suff = '\0'; - } - } + dropExtension(prog, ".exe"); +#elif defined(wasm32_HOST_ARCH) + dropExtension(prog, ".wasm"); #endif stem = prog; } diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c index 4cac10ba156dda2ecd9cb54cc3fbc955f25085b2..6a1faf7a30797e7afefd57121d583e480a644b10 100644 --- a/rts/RtsUtils.c +++ b/rts/RtsUtils.c @@ -456,3 +456,15 @@ void checkFPUStack(void) } #endif } + +// Drop the given extension from a filepath. +void dropExtension(char *path, const char *extension) { + int ext_len = strlen(extension); + int path_len = strlen(path); + if (ext_len < path_len) { + char *s = &path[path_len - ext_len]; + if (strcmp(s, extension) == 0) { + *s = '\0'; + } + } +} diff --git a/rts/RtsUtils.h b/rts/RtsUtils.h index 2f4827c5263d12f5b89d2072da6c35fa05b637dc..095f8d1bc7a7475c0808896da21b88bbb5cbdc64 100644 --- a/rts/RtsUtils.h +++ b/rts/RtsUtils.h @@ -62,4 +62,7 @@ void checkFPUStack(void); #define xstr(s) str(s) #define str(s) #s +// Drop the given extension from a filepath. +void dropExtension(char *path, const char *extension); + #include "EndPrivate.h"