aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-io/source/file_utils_shared.c
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/restricted/aws/aws-c-io/source/file_utils_shared.c
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
downloadydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-io/source/file_utils_shared.c')
-rw-r--r--contrib/restricted/aws/aws-c-io/source/file_utils_shared.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/contrib/restricted/aws/aws-c-io/source/file_utils_shared.c b/contrib/restricted/aws/aws-c-io/source/file_utils_shared.c
index 091b27a66e..00a5f38800 100644
--- a/contrib/restricted/aws/aws-c-io/source/file_utils_shared.c
+++ b/contrib/restricted/aws/aws-c-io/source/file_utils_shared.c
@@ -1,68 +1,68 @@
-/**
- * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0.
- */
-
-#include <aws/io/file_utils.h>
-
-#include <aws/common/environment.h>
-#include <aws/common/string.h>
-#include <aws/io/logging.h>
-
-#include <errno.h>
-#include <stdio.h>
-
-#ifdef _MSC_VER
-# pragma warning(disable : 4996) /* Disable warnings about fopen() being insecure */
-#endif /* _MSC_VER */
-
-int aws_byte_buf_init_from_file(struct aws_byte_buf *out_buf, struct aws_allocator *alloc, const char *filename) {
- AWS_ZERO_STRUCT(*out_buf);
- FILE *fp = fopen(filename, "rb");
-
- if (fp) {
- if (fseek(fp, 0L, SEEK_END)) {
- AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to seek file %s with errno %d", filename, errno);
- fclose(fp);
- return aws_translate_and_raise_io_error(errno);
- }
-
- size_t allocation_size = (size_t)ftell(fp) + 1;
- /* Tell the user that we allocate here and if success they're responsible for the free. */
- if (aws_byte_buf_init(out_buf, alloc, allocation_size)) {
- fclose(fp);
- return AWS_OP_ERR;
- }
-
- /* Ensure compatibility with null-terminated APIs, but don't consider
- * the null terminator part of the length of the payload */
- out_buf->len = out_buf->capacity - 1;
- out_buf->buffer[out_buf->len] = 0;
-
- if (fseek(fp, 0L, SEEK_SET)) {
- AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to seek file %s with errno %d", filename, errno);
- aws_byte_buf_clean_up(out_buf);
- fclose(fp);
- return aws_translate_and_raise_io_error(errno);
- }
-
- size_t read = fread(out_buf->buffer, 1, out_buf->len, fp);
- fclose(fp);
- if (read < out_buf->len) {
- AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to read file %s with errno %d", filename, errno);
- aws_secure_zero(out_buf->buffer, out_buf->len);
- aws_byte_buf_clean_up(out_buf);
- return aws_raise_error(AWS_IO_FILE_VALIDATION_FAILURE);
- }
-
- return AWS_OP_SUCCESS;
- }
-
- AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to open file %s with errno %d", filename, errno);
-
- return aws_translate_and_raise_io_error(errno);
-}
-
-bool aws_is_any_directory_separator(char value) {
- return value == '\\' || value == '/';
-}
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+
+#include <aws/io/file_utils.h>
+
+#include <aws/common/environment.h>
+#include <aws/common/string.h>
+#include <aws/io/logging.h>
+
+#include <errno.h>
+#include <stdio.h>
+
+#ifdef _MSC_VER
+# pragma warning(disable : 4996) /* Disable warnings about fopen() being insecure */
+#endif /* _MSC_VER */
+
+int aws_byte_buf_init_from_file(struct aws_byte_buf *out_buf, struct aws_allocator *alloc, const char *filename) {
+ AWS_ZERO_STRUCT(*out_buf);
+ FILE *fp = fopen(filename, "rb");
+
+ if (fp) {
+ if (fseek(fp, 0L, SEEK_END)) {
+ AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to seek file %s with errno %d", filename, errno);
+ fclose(fp);
+ return aws_translate_and_raise_io_error(errno);
+ }
+
+ size_t allocation_size = (size_t)ftell(fp) + 1;
+ /* Tell the user that we allocate here and if success they're responsible for the free. */
+ if (aws_byte_buf_init(out_buf, alloc, allocation_size)) {
+ fclose(fp);
+ return AWS_OP_ERR;
+ }
+
+ /* Ensure compatibility with null-terminated APIs, but don't consider
+ * the null terminator part of the length of the payload */
+ out_buf->len = out_buf->capacity - 1;
+ out_buf->buffer[out_buf->len] = 0;
+
+ if (fseek(fp, 0L, SEEK_SET)) {
+ AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to seek file %s with errno %d", filename, errno);
+ aws_byte_buf_clean_up(out_buf);
+ fclose(fp);
+ return aws_translate_and_raise_io_error(errno);
+ }
+
+ size_t read = fread(out_buf->buffer, 1, out_buf->len, fp);
+ fclose(fp);
+ if (read < out_buf->len) {
+ AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to read file %s with errno %d", filename, errno);
+ aws_secure_zero(out_buf->buffer, out_buf->len);
+ aws_byte_buf_clean_up(out_buf);
+ return aws_raise_error(AWS_IO_FILE_VALIDATION_FAILURE);
+ }
+
+ return AWS_OP_SUCCESS;
+ }
+
+ AWS_LOGF_ERROR(AWS_LS_IO_FILE_UTILS, "static: Failed to open file %s with errno %d", filename, errno);
+
+ return aws_translate_and_raise_io_error(errno);
+}
+
+bool aws_is_any_directory_separator(char value) {
+ return value == '\\' || value == '/';
+}