summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/spawn.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index d611b2cd0..c15f6fbf8 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -1218,23 +1218,25 @@ err:
static const char *cmd_exe_path = NULL;
-static void init_cmd_exe_path(void)
+static void
+init_cmd_exe_path(void)
{
char sysdir[NT_MAX_PATH];
- char cmdname[] = "cmd.exe";
- unsigned int nchars;
-
- if ((nchars = GetSystemDirectoryA(sysdir, sizeof sysdir)) < sizeof sysdir) {
- unsigned int total = nchars + 1 + sizeof cmdname + 1;
- char *path = static_cast<char *>(cmalloc_abort(HEAP_STR, total));
- snprintf(path, total, "%s\\%s", sysdir, cmdname);
- cmd_exe_path = path;
- }
+ char cmdname[] = "\\cmd.exe";
+ unsigned int nchars = GetSystemDirectoryA(sysdir, sizeof sysdir);
+
+ if (nchars < sizeof sysdir)
+ {
+ unsigned int total = nchars + sizeof cmdname;
+ char *path = static_cast<char *>(cmalloc_abort(HEAP_STR, total));
+ snprintf(path, total, "%s%s", sysdir, cmdname);
+ cmd_exe_path = path;
+ }
}
const char *get_cmd_exe_path()
{
static pthread_once_t cmd_exe_once = PTHREAD_ONCE_INIT;
- pthread_once (&cmd_exe_once, init_cmd_exe_path);
+ pthread_once(&cmd_exe_once, init_cmd_exe_path);
return cmd_exe_path;
}