From 5162ce7419fe443769dc1637f7c74470df8736f8 Mon Sep 17 00:00:00 2001 From: Paze AI Date: Sun, 16 Aug 2026 14:49:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20pcmake=20output=20=E5=90=8E=E7=BC=80?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - output = demo -> demo.exe (自动追加 .exe) - output = demo.exe -> demo.exe (不重复追加) - output = demo.EXE -> demo.EXE (大小写不敏感) - clean 命令同步修复 --- tools/pcmake.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/tools/pcmake.c b/tools/pcmake.c index dfd2d53..fcd9d6b 100644 --- a/tools/pcmake.c +++ b/tools/pcmake.c @@ -190,6 +190,29 @@ static int file_exists(const char *f) { return 0; } +/* build the output file name: append .exe on Windows only if + the configured name does not already end with .exe (case-insensitive) */ +static int ends_with_exe(const char *s) +{ + int n = (int)strlen(s); + if (n < 4) return 0; + s += n - 4; + return (tolower((unsigned char)s[1])=='e') + && (tolower((unsigned char)s[2])=='x') && (tolower((unsigned char)s[3])=='e'); +} + +static void make_output_name(const char *in, char *out, int outsize) +{ + int n = (int)strlen(in); + if (n >= outsize) n = outsize - 1; + memcpy(out, in, n); + out[n] = 0; +#ifdef _WIN32 + if (!ends_with_exe(out)) + strncat(out, ".exe", outsize - n - 1); +#endif +} + /* run a command line; Windows uses CreateProcess to handle quoted paths with spaces correctly (system() misbehaves) */ static int run_command(const char *cmd) { @@ -275,11 +298,7 @@ int main(int argc, char **argv) { } { char outbuf[512]; - strncpy(outbuf, g_output, sizeof outbuf - 1); - outbuf[sizeof outbuf - 1] = 0; -#ifdef _WIN32 - strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1); -#endif + make_output_name(g_output, outbuf, sizeof outbuf); printf(" rm %s\n", outbuf); remove(outbuf); } @@ -323,11 +342,7 @@ int main(int argc, char **argv) { len += snprintf(cmd + len, sizeof cmd - len, " -l%s", g_libs[i]); { char outbuf[512]; - strncpy(outbuf, g_output, sizeof outbuf - 1); - outbuf[sizeof outbuf - 1] = 0; -#ifdef _WIN32 - strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1); -#endif + make_output_name(g_output, outbuf, sizeof outbuf); len += snprintf(cmd + len, sizeof cmd - len, " -o \"%s\"", outbuf); } printf(" link %s\n", g_output); @@ -337,12 +352,10 @@ int main(int argc, char **argv) { return 1; } - printf("pcmake: build OK -> %s%s\n", g_output, -#ifdef _WIN32 - ".exe" -#else - "" -#endif - ); + { + char outbuf[512]; + make_output_name(g_output, outbuf, sizeof outbuf); + printf("pcmake: build OK -> %s\n", outbuf); + } return 0; }