Skip to content

Commit c13aaf8

Browse files
committed
Force cmd.exe's default prompt if it's unset.
1 parent c2113de commit c13aaf8

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

clink/dll/shell_cmd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,23 @@ static void tag_prompt()
303303
// can identify console writes that are the prompt.
304304

305305
static const char* name = "prompt";
306+
static const char* default_prompt = "$p$g";
306307
static const int buffer_size = 0x10000;
307308

308309
int tag_size;
309310
char* buffer;
311+
char* suffix;
310312

311313
buffer = malloc(buffer_size);
312314
tag_size = strlen(g_prompt_tag_hidden);
315+
suffix = buffer + tag_size;
313316

314317
strcpy(buffer, g_prompt_tag_hidden);
315-
GetEnvironmentVariableA(name, buffer + tag_size, buffer_size - tag_size);
318+
if (!GetEnvironmentVariableA(name, suffix, buffer_size - tag_size))
319+
{
320+
SetEnvironmentVariableA(name, default_prompt);
321+
GetEnvironmentVariableA(name, suffix, buffer_size - tag_size);
322+
}
316323
SetEnvironmentVariableA(name, buffer);
317324

318325
free(buffer);

0 commit comments

Comments
 (0)