summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/process_common.c
diff options
context:
space:
mode:
authororivej <[email protected]>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/restricted/aws/aws-c-common/source/process_common.c
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/process_common.c')
-rw-r--r--contrib/restricted/aws/aws-c-common/source/process_common.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/process_common.c b/contrib/restricted/aws/aws-c-common/source/process_common.c
index e2d266edba2..9b734c46f81 100644
--- a/contrib/restricted/aws/aws-c-common/source/process_common.c
+++ b/contrib/restricted/aws/aws-c-common/source/process_common.c
@@ -1,82 +1,82 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/common/process.h>
-#include <aws/common/string.h>
-
-#include <stdio.h>
-#include <sys/types.h>
-
-#define MAX_BUFFER_SIZE (2048)
-
-int aws_run_command_result_init(struct aws_allocator *allocator, struct aws_run_command_result *result) {
- if (!allocator || !result) {
- return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
- }
- AWS_ZERO_STRUCT(*result);
- return AWS_OP_SUCCESS;
-}
-
-void aws_run_command_result_cleanup(struct aws_run_command_result *result) {
- if (!result) {
- return;
- }
- aws_string_destroy_secure(result->std_out);
- aws_string_destroy_secure(result->std_err);
-}
-
-int aws_run_command(
- struct aws_allocator *allocator,
- struct aws_run_command_options *options,
- struct aws_run_command_result *result) {
-
- AWS_FATAL_ASSERT(allocator);
- AWS_FATAL_ASSERT(options);
- AWS_FATAL_ASSERT(result);
-
- FILE *output_stream;
- char output_buffer[MAX_BUFFER_SIZE];
- struct aws_byte_buf result_buffer;
- int ret = AWS_OP_ERR;
- if (aws_byte_buf_init(&result_buffer, allocator, MAX_BUFFER_SIZE)) {
- goto on_finish;
- }
-
-#ifdef _WIN32
- output_stream = _popen(options->command, "r");
-#else
- output_stream = popen(options->command, "r");
-#endif
-
- if (output_stream) {
- while (!feof(output_stream)) {
- if (fgets(output_buffer, MAX_BUFFER_SIZE, output_stream) != NULL) {
- struct aws_byte_cursor cursor = aws_byte_cursor_from_c_str(output_buffer);
- if (aws_byte_buf_append_dynamic(&result_buffer, &cursor)) {
- goto on_finish;
- }
- }
- }
-#ifdef _WIN32
- result->ret_code = _pclose(output_stream);
-#else
- result->ret_code = pclose(output_stream);
-#endif
- }
-
- struct aws_byte_cursor trim_cursor = aws_byte_cursor_from_buf(&result_buffer);
- struct aws_byte_cursor trimmed_cursor = aws_byte_cursor_trim_pred(&trim_cursor, aws_char_is_space);
- if (trimmed_cursor.len) {
- result->std_out = aws_string_new_from_array(allocator, trimmed_cursor.ptr, trimmed_cursor.len);
- if (!result->std_out) {
- goto on_finish;
- }
- }
- ret = AWS_OP_SUCCESS;
-
-on_finish:
- aws_byte_buf_clean_up_secure(&result_buffer);
- return ret;
-}
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/common/process.h>
+#include <aws/common/string.h>
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#define MAX_BUFFER_SIZE (2048)
+
+int aws_run_command_result_init(struct aws_allocator *allocator, struct aws_run_command_result *result) {
+ if (!allocator || !result) {
+ return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+ AWS_ZERO_STRUCT(*result);
+ return AWS_OP_SUCCESS;
+}
+
+void aws_run_command_result_cleanup(struct aws_run_command_result *result) {
+ if (!result) {
+ return;
+ }
+ aws_string_destroy_secure(result->std_out);
+ aws_string_destroy_secure(result->std_err);
+}
+
+int aws_run_command(
+ struct aws_allocator *allocator,
+ struct aws_run_command_options *options,
+ struct aws_run_command_result *result) {
+
+ AWS_FATAL_ASSERT(allocator);
+ AWS_FATAL_ASSERT(options);
+ AWS_FATAL_ASSERT(result);
+
+ FILE *output_stream;
+ char output_buffer[MAX_BUFFER_SIZE];
+ struct aws_byte_buf result_buffer;
+ int ret = AWS_OP_ERR;
+ if (aws_byte_buf_init(&result_buffer, allocator, MAX_BUFFER_SIZE)) {
+ goto on_finish;
+ }
+
+#ifdef _WIN32
+ output_stream = _popen(options->command, "r");
+#else
+ output_stream = popen(options->command, "r");
+#endif
+
+ if (output_stream) {
+ while (!feof(output_stream)) {
+ if (fgets(output_buffer, MAX_BUFFER_SIZE, output_stream) != NULL) {
+ struct aws_byte_cursor cursor = aws_byte_cursor_from_c_str(output_buffer);
+ if (aws_byte_buf_append_dynamic(&result_buffer, &cursor)) {
+ goto on_finish;
+ }
+ }
+ }
+#ifdef _WIN32
+ result->ret_code = _pclose(output_stream);
+#else
+ result->ret_code = pclose(output_stream);
+#endif
+ }
+
+ struct aws_byte_cursor trim_cursor = aws_byte_cursor_from_buf(&result_buffer);
+ struct aws_byte_cursor trimmed_cursor = aws_byte_cursor_trim_pred(&trim_cursor, aws_char_is_space);
+ if (trimmed_cursor.len) {
+ result->std_out = aws_string_new_from_array(allocator, trimmed_cursor.ptr, trimmed_cursor.len);
+ if (!result->std_out) {
+ goto on_finish;
+ }
+ }
+ ret = AWS_OP_SUCCESS;
+
+on_finish:
+ aws_byte_buf_clean_up_secure(&result_buffer);
+ return ret;
+}