Split commander windows and posix implementations
This commit is contained in:
parent
12f182f0cf
commit
a546a09565
@ -11,11 +11,11 @@
|
||||
#define OUT_BUF_LEN 4096
|
||||
|
||||
internal inline CMDError build_command_from_args(char *cmd, u64 buf_len, va_list args);
|
||||
internal inline CMDResult execute_command(const char *cmd, CMDOutHandling out_handling,
|
||||
char *out_buf, u64 buf_size);
|
||||
internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling,
|
||||
char *out_buf, u64 buf_size);
|
||||
internal inline CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
internal inline CMDResult execute_command(const char *cmd, CMDOutHandling out_handling, char *out_buf,
|
||||
u64 buf_size);
|
||||
internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, char *out_buf,
|
||||
u64 buf_size);
|
||||
extern CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
|
||||
CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...) {
|
||||
va_list args;
|
||||
@ -117,25 +117,3 @@ internal inline CMDError get_command_output(FILE *fp,
|
||||
|
||||
return SHELL_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
internal inline CMDError get_output_status(FILE *fp, i32 *status_out) {
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
if (!feof(fp)) {
|
||||
// Ensure process is closed on failure
|
||||
wapp_shell_utils_pclose(fp);
|
||||
return SHELL_ERR_PROC_EXIT_FAIL;
|
||||
}
|
||||
#endif /* ifdef WAPP_PLATFORM_WINDOWS */
|
||||
|
||||
*status_out = wapp_shell_utils_pclose(fp);
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
if (!WIFEXITED(*status_out)) {
|
||||
return SHELL_ERR_PROC_EXIT_FAIL;
|
||||
}
|
||||
|
||||
*status_out = WEXITSTATUS(*status_out);
|
||||
#endif /* ifdef WAPP_PLATFORM_WINDOWS */
|
||||
|
||||
return SHELL_ERR_NO_ERROR;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define COMMANDER_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "commander_output.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -14,32 +14,6 @@ BEGIN_C_LINKAGE
|
||||
#define wapp_shell_commander_execute(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, ...) \
|
||||
run_command(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, __VA_ARGS__, "2>&1", NULL)
|
||||
|
||||
typedef enum {
|
||||
SHELL_OUTPUT_DISCARD,
|
||||
SHELL_OUTPUT_PRINT,
|
||||
SHELL_OUTPUT_CAPTURE,
|
||||
} CMDOutHandling;
|
||||
|
||||
typedef enum {
|
||||
SHELL_ERR_NO_ERROR,
|
||||
SHELL_ERR_CMD_BUF_FULL,
|
||||
SHELL_ERR_PROC_START_FAIL,
|
||||
SHELL_ERR_OUT_BUF_FULL,
|
||||
SHELL_ERR_PROC_EXIT_FAIL,
|
||||
} CMDError;
|
||||
|
||||
typedef struct commander_result CMDResult;
|
||||
struct commander_result {
|
||||
i32 exit_code;
|
||||
CMDError error;
|
||||
bool exited;
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
#include "misc_utils.h"
|
||||
wapp_misc_utils_padding_size(sizeof(bool) + sizeof(i32) + sizeof(CMDError));
|
||||
#endif // !WAPP_PLATFORM_WINDOWS
|
||||
};
|
||||
|
||||
CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
42
src/common/shell/commander/commander_output.h
Normal file
42
src/common/shell/commander/commander_output.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef COMMANDER_OUTPUT_H
|
||||
#define COMMANDER_OUTPUT_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef enum {
|
||||
SHELL_OUTPUT_DISCARD,
|
||||
SHELL_OUTPUT_PRINT,
|
||||
SHELL_OUTPUT_CAPTURE,
|
||||
} CMDOutHandling;
|
||||
|
||||
typedef enum {
|
||||
SHELL_ERR_NO_ERROR,
|
||||
SHELL_ERR_CMD_BUF_FULL,
|
||||
SHELL_ERR_PROC_START_FAIL,
|
||||
SHELL_ERR_OUT_BUF_FULL,
|
||||
SHELL_ERR_PROC_EXIT_FAIL,
|
||||
} CMDError;
|
||||
|
||||
typedef struct commander_result CMDResult;
|
||||
struct commander_result {
|
||||
i32 exit_code;
|
||||
CMDError error;
|
||||
bool exited;
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
#include "misc_utils.h"
|
||||
wapp_misc_utils_padding_size(sizeof(bool) + sizeof(i32) + sizeof(CMDError));
|
||||
#endif // !WAPP_PLATFORM_WINDOWS
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !COMMANDER_OUTPUT_H
|
23
src/common/shell/commander/posix/commander_posix.c
Normal file
23
src/common/shell/commander/posix/commander_posix.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
|
||||
#include "commander_output.h"
|
||||
#include "shell_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
CMDError get_output_status(FILE *fp, i32 *status_out) {
|
||||
*status_out = wapp_shell_utils_pclose(fp);
|
||||
|
||||
if (!WIFEXITED(*status_out)) {
|
||||
return SHELL_ERR_PROC_EXIT_FAIL;
|
||||
}
|
||||
|
||||
*status_out = WEXITSTATUS(*status_out);
|
||||
|
||||
return SHELL_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
#endif // !WAPP_PLATFORM_POSIX
|
22
src/common/shell/commander/win/commander_win.c
Normal file
22
src/common/shell/commander/win/commander_win.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#include "commander_output.h"
|
||||
#include "shell_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
CMDError get_output_status(FILE *fp, i32 *status_out) {
|
||||
if (!feof(fp)) {
|
||||
// Ensure process is closed on failure
|
||||
wapp_shell_utils_pclose(fp);
|
||||
return SHELL_ERR_PROC_EXIT_FAIL;
|
||||
}
|
||||
|
||||
*status_out = wapp_shell_utils_pclose(fp);
|
||||
|
||||
return SHELL_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
#endif // !WAPP_PLATFORM_WINDOWS
|
Loading…
Reference in New Issue
Block a user