Fix for arithmetic promotion of aliases. Some work towards $exec scripting.

This commit is contained in:
Christoffer Lerno
2023-08-10 17:14:29 +02:00
parent 01a89e2145
commit 6d870fbef0
10 changed files with 139 additions and 10 deletions

View File

@@ -611,6 +611,46 @@ const char *execute_cmd(const char *cmd)
return str_trim(output);
}
bool execute_cmd_failable(const char *cmd, const char **result)
{
char buffer[BUFSIZE];
char *output = "";
FILE *process = NULL;
#if (_MSC_VER)
if (!(process = _wpopen(win_utf8to16(cmd), L"r"))) return false;
#else
if (!(process = popen(cmd, "r"))) return false;
#endif
while (fgets(buffer, BUFSIZE - 1, process))
{
output = str_cat(output, buffer);
}
#if PLATFORM_WINDOWS
int err = _pclose(process);
#else
int err = pclose(process);
#endif
if (err) return false;
while (output[0] != 0)
{
switch (output[0])
{
case ' ':
case '\t':
case '\n':
case '\r':
output++;
continue;
default:
break;
}
break;
}
*result = str_trim(output);
return true;
}
#if PLATFORM_WINDOWS
char *realpath(const char *path, char *const resolved_path)

View File

@@ -15,6 +15,8 @@
const char *download_file(const char *url, const char *resource, const char *file_path);
#endif
extern const char *compiler_exe_name;
typedef struct StringSlice_
{
const char *ptr;
@@ -84,6 +86,7 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi
const char *file_append_path(const char *path, const char *name);
const char *execute_cmd(const char *cmd);
bool execute_cmd_failable(const char *cmd, const char **result);
void *cmalloc(size_t size);
void *ccalloc(size_t size, size_t elements);
void memory_init(void);