diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:05:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:05:51 +0000 |
commit | 5d1646d90e1f2cceb9f0828f4b28318cd0ec7744 (patch) | |
tree | a94efe259b9009378be6d90eb30d2b019d95c194 /tools/power/acpi/common/cmfsize.c | |
parent | Initial commit. (diff) | |
download | linux-5d1646d90e1f2cceb9f0828f4b28318cd0ec7744.tar.xz linux-5d1646d90e1f2cceb9f0828f4b28318cd0ec7744.zip |
Adding upstream version 5.10.209.upstream/5.10.209upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/power/acpi/common/cmfsize.c')
-rw-r--r-- | tools/power/acpi/common/cmfsize.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/power/acpi/common/cmfsize.c b/tools/power/acpi/common/cmfsize.c new file mode 100644 index 000000000..d1d18ff5c --- /dev/null +++ b/tools/power/acpi/common/cmfsize.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 +/****************************************************************************** + * + * Module Name: cfsize - Common get file size function + * + * Copyright (C) 2000 - 2020, Intel Corp. + * + *****************************************************************************/ + +#include <acpi/acpi.h> +#include "accommon.h" +#include "acapps.h" + +#define _COMPONENT ACPI_TOOLS +ACPI_MODULE_NAME("cmfsize") + +/******************************************************************************* + * + * FUNCTION: cm_get_file_size + * + * PARAMETERS: file - Open file descriptor + * + * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) + * + * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. + * Does not disturb the current file pointer. + * + ******************************************************************************/ +u32 cm_get_file_size(ACPI_FILE file) +{ + long file_size; + long current_offset; + acpi_status status; + + /* Save the current file pointer, seek to EOF to obtain file size */ + + current_offset = ftell(file); + if (current_offset < 0) { + goto offset_error; + } + + status = fseek(file, 0, SEEK_END); + if (ACPI_FAILURE(status)) { + goto seek_error; + } + + file_size = ftell(file); + if (file_size < 0) { + goto offset_error; + } + + /* Restore original file pointer */ + + status = fseek(file, current_offset, SEEK_SET); + if (ACPI_FAILURE(status)) { + goto seek_error; + } + + return ((u32)file_size); + +offset_error: + fprintf(stderr, "Could not get file offset\n"); + return (ACPI_UINT32_MAX); + +seek_error: + fprintf(stderr, "Could not set file offset\n"); + return (ACPI_UINT32_MAX); +} |