39#if defined(__GNUC__) || defined(__clang__)
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Wsign-conversion"
47 int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
48 WCHAR *ucs16 =
gc_malloc(n *
sizeof(WCHAR),
false,
gc);
49 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, ucs16, n);
54#define CMD_QUOTE_TRIGGERS " &|<>^%()!"
59 for (
const char *c = str; *c !=
'\0'; ++c)
83 for (i = 0; i < a->
argc; ++i)
85 const char *arg = a->
argv[i];
86 const size_t len = strlen(arg);
98 for (i = 0; i < a->
argc; ++i)
100 const char *arg = a->
argv[i];
127 int n = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL);
133 WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, n, NULL, NULL);
139#if defined(__GNUC__) || defined(__clang__)
140#pragma GCC diagnostic pop
165 const int c1 = pre[i];
181 return c2 ==
'\0' || c2 ==
'.';
187 if (c1 != tolower(c2))
231 static char tmpdir[MAX_PATH];
232 WCHAR wtmpdir[MAX_PATH];
234 if (!GetTempPathW(_countof(wtmpdir), wtmpdir))
239 int ret = WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL);
246 if ((
unsigned int)ret >
sizeof(tmpdir))
248 msg(
M_WARN,
"Could not get temporary directory. Path is too long."
249 " Consider using --tmp-dir");
253 WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, tmpdir,
sizeof(tmpdir), NULL, NULL);
260 size_t dir_len = wcslen(dir);
264 if (dir_len <= 1 || wcsnicmp(dir, path, dir_len) != 0)
274 if (dir[dir_len - 1] == L
'\\' || dir[dir_len - 1] == L
'/')
279 WCHAR next = path[dir_len];
280 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)