diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-06-28 06:04:57 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-06-28 06:04:57 +0000 |
| commit | 18cdc70abbebc2e8206945e6b170cf9f627da284 (patch) | |
| tree | 7fed0dd5455546fa56df899ded5938220237029d /src/cmd_out.c | |
| parent | 64e61e9b5de7546dc3bcbca577a029629774e108 (diff) | |
formatted code according to new guidelines
Diffstat (limited to 'src/cmd_out.c')
| -rw-r--r-- | src/cmd_out.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/cmd_out.c b/src/cmd_out.c index 269d6f2..bc371e0 100644 --- a/src/cmd_out.c +++ b/src/cmd_out.c @@ -26,37 +26,35 @@ #include "cmd_out.h" char* cmd_out(const char *cmd) { - FILE *pipe = popen(cmd, "r"); - if (!pipe) { - return strdup(""); - } - - char buffer[128]; - size_t total_size = 0; - size_t capacity = 256; - char *result = malloc(capacity); - if (!result) { - pclose(pipe); - return strdup(""); - } - result[0] = '\0'; - - while (fgets(buffer, sizeof(buffer), pipe) != NULL) { - size_t len = strlen(buffer); - if (total_size + len + 1 > capacity) { - capacity *= 2; - char *new_result = realloc(result, capacity); - if (!new_result) { - free(result); - pclose(pipe); - return strdup(""); - } - result = new_result; - } - strcat(result, buffer); - total_size += len; - } - - pclose(pipe); - return result; + FILE *pipe = popen(cmd, "r"); + if (!pipe) return strdup(""); + + char buffer[128]; + size_t total_size = 0; + size_t capacity = 256; + char *result = malloc(capacity); + if (!result) { + pclose(pipe); + return strdup(""); + } + result[0] = '\0'; + + while (fgets(buffer, sizeof(buffer), pipe) != NULL) { + size_t len = strlen(buffer); + if (total_size + len + 1 > capacity) { + capacity *= 2; + char *new_result = realloc(result, capacity); + if (!new_result) { + free(result); + pclose(pipe); + return strdup(""); + } + result = new_result; + } + strcat(result, buffer); + total_size += len; + } + + pclose(pipe); + return result; }
\ No newline at end of file |
