diff --git a/src/asmsx.c b/src/asmsx.c index 41aaac5..47132e8 100644 --- a/src/asmsx.c +++ b/src/asmsx.c @@ -589,7 +589,7 @@ void error_message(int n, char *fname_src, int lines) { } else { fprintf(stderr, "%s", error_buffer); } - remove("~tmppre.?"); + remove_temporary_files(); exit(n + 1); } @@ -694,3 +694,19 @@ int isDirectory(const char *path) { return 0; return S_ISDIR(statbuf.st_mode); } + +/* Remove temporary preprocessor files created during assembly + * These files are created with these names: ~tmppre.0, ~tmppre.1, ~tmppre.2, ~tmppre.3 + * and are no longer needed after assembly is complete. + */ +void remove_temporary_files(void) { + char filename[PATH_MAX]; + int i; + + for (i = 0; i <= 3; i++) { + snprintf(filename, PATH_MAX - 1, "~tmppre.%d", i); + if (remove(filename) == 0 && verbose) { + printf("Removed temporary file: %s\n", filename); + } + } +} diff --git a/src/asmsx.h b/src/asmsx.h index 9749fa7..b6f33bd 100644 --- a/src/asmsx.h +++ b/src/asmsx.h @@ -58,3 +58,4 @@ extern void error_message(int n, char* fname_src, int lines); extern void warning_message(int n, char* fname_src, int lines, int pass, int* warnings); extern char* replaceWord(const char* s, const char* oldW, const char* newW, int* count); extern int isDirectory(const char *path); +extern void remove_temporary_files(void); diff --git a/src/dura.y b/src/dura.y index 1bf504b..3eded31 100644 --- a/src/dura.y +++ b/src/dura.y @@ -4337,7 +4337,7 @@ void finalize() else printf("\n"); - remove("~tmppre.*"); + remove_temporary_files(); exit(0); } @@ -4699,6 +4699,6 @@ int main(int argc, char *argv[]) { yyparse(); - remove("~tmppre.?"); + remove_temporary_files(); return 0; }