42 int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
43 WCHAR *ucs16 =
gc_malloc(n *
sizeof(WCHAR),
false,
gc);
44 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, ucs16, n);
49#define CMD_QUOTE_TRIGGERS " &|<>^%()!"
54 for (
const char *c = str; *c !=
'\0'; ++c)
78 for (i = 0; i < a->
argc; ++i)
80 const char *arg = a->
argv[i];
81 const size_t len = strlen(arg);
93 for (i = 0; i < a->
argc; ++i)
95 const char *arg = a->
argv[i];
122 int n = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL);
128 WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, n, NULL, NULL);
156 const int c1 = pre[i];
172 return c2 ==
'\0' || c2 ==
'.';
178 if (c1 != tolower(c2))
222 static char tmpdir[MAX_PATH];
223 WCHAR wtmpdir[MAX_PATH];
225 if (!GetTempPathW(_countof(wtmpdir), wtmpdir))
230 int ret = WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL);
237 if ((
unsigned int)ret >
sizeof(tmpdir))
239 msg(
M_WARN,
"Could not get temporary directory. Path is too long."
240 " Consider using --tmp-dir");
244 WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, tmpdir,
sizeof(tmpdir), NULL, NULL);
251 size_t dir_len = wcslen(dir);
255 if (dir_len <= 1 || wcsnicmp(dir, path, dir_len) != 0)
265 if (dir[dir_len - 1] == L
'\\' || dir[dir_len - 1] == L
'/')
270 WCHAR next = path[dir_len];
271 return next == L
'\\' || next == L
'/';
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
Buffer management functions and garbage collection.
#define CC_EXCLAMATION
exclamation mark
#define CC_PERCENT
percent sign
#define CC_DOUBLE_QUOTE
double quote
#define BSTR(buf)
Return the buffer content pointer cast to char *.
#define CC_CRLF
carriage return or newline
static void check_malloc_return(void *p)
Abort if a memory allocation returned NULL.
#define CC_PRINT
printable (>= 32, != 127)
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
bool win_path_in_dir(const WCHAR *path, const WCHAR *dir)
Check whether path resides within directory dir.
char * utf16to8(const wchar_t *utf16, struct gc_arena *gc)
static bool cmp_prefix(const char *str, const bool n, const char *pre)
bool win_safe_filename(const char *fn)
const char * win_get_tempdir(void)
#define CMD_QUOTE_TRIGGERS
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
WCHAR * wide_cmd_line(const struct argv *a, struct gc_arena *gc)
static bool argv_element_needs_quotes(const char *str)