diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/restricted/aws/aws-c-io/source/posix/file_utils.c | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-io/source/posix/file_utils.c')
-rw-r--r-- | contrib/restricted/aws/aws-c-io/source/posix/file_utils.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/contrib/restricted/aws/aws-c-io/source/posix/file_utils.c b/contrib/restricted/aws/aws-c-io/source/posix/file_utils.c index fcb96260eb..03b5f6c734 100644 --- a/contrib/restricted/aws/aws-c-io/source/posix/file_utils.c +++ b/contrib/restricted/aws/aws-c-io/source/posix/file_utils.c @@ -1,69 +1,69 @@ -/** - * 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 <errno.h> -#include <sys/stat.h> -#include <unistd.h> - -char aws_get_platform_directory_separator(void) { - return '/'; -} - -AWS_STATIC_STRING_FROM_LITERAL(s_home_env_var, "HOME"); - -struct aws_string *aws_get_home_directory(struct aws_allocator *allocator) { - - /* ToDo: check getpwuid_r if environment check fails */ - struct aws_string *home_env_var_value = NULL; - if (aws_get_environment_value(allocator, s_home_env_var, &home_env_var_value) == 0 && home_env_var_value != NULL) { - return home_env_var_value; - } - - return NULL; -} - -bool aws_path_exists(const char *path) { - struct stat buffer; - return stat(path, &buffer) == 0; -} - -int aws_fseek(FILE *file, aws_off_t offset, int whence) { - - int result = -#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L - fseeko(file, offset, whence); -#else - fseek(file, offset, whence); -#endif - - if (result != 0) { - return aws_translate_and_raise_io_error(errno); - } - - return AWS_OP_SUCCESS; -} - -int aws_file_get_length(FILE *file, int64_t *length) { - - struct stat file_stats; - - int fd = fileno(file); - if (fd == -1) { - return aws_raise_error(AWS_IO_INVALID_FILE_HANDLE); - } - - if (fstat(fd, &file_stats)) { - return aws_translate_and_raise_io_error(errno); - } - - *length = file_stats.st_size; - - return AWS_OP_SUCCESS; -} +/** + * 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 <errno.h> +#include <sys/stat.h> +#include <unistd.h> + +char aws_get_platform_directory_separator(void) { + return '/'; +} + +AWS_STATIC_STRING_FROM_LITERAL(s_home_env_var, "HOME"); + +struct aws_string *aws_get_home_directory(struct aws_allocator *allocator) { + + /* ToDo: check getpwuid_r if environment check fails */ + struct aws_string *home_env_var_value = NULL; + if (aws_get_environment_value(allocator, s_home_env_var, &home_env_var_value) == 0 && home_env_var_value != NULL) { + return home_env_var_value; + } + + return NULL; +} + +bool aws_path_exists(const char *path) { + struct stat buffer; + return stat(path, &buffer) == 0; +} + +int aws_fseek(FILE *file, aws_off_t offset, int whence) { + + int result = +#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L + fseeko(file, offset, whence); +#else + fseek(file, offset, whence); +#endif + + if (result != 0) { + return aws_translate_and_raise_io_error(errno); + } + + return AWS_OP_SUCCESS; +} + +int aws_file_get_length(FILE *file, int64_t *length) { + + struct stat file_stats; + + int fd = fileno(file); + if (fd == -1) { + return aws_raise_error(AWS_IO_INVALID_FILE_HANDLE); + } + + if (fstat(fd, &file_stats)) { + return aws_translate_and_raise_io_error(errno); + } + + *length = file_stats.st_size; + + return AWS_OP_SUCCESS; +} |