// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.01/******************************************************************************2*3* Module Name: cmfsize - Common get file size function4*5* Copyright (C) 2000 - 2025, Intel Corp.6*7*****************************************************************************/89#include <acpi/acpi.h>10#include "accommon.h"11#include "acapps.h"1213#define _COMPONENT ACPI_TOOLS14ACPI_MODULE_NAME("cmfsize")1516/*******************************************************************************17*18* FUNCTION: cm_get_file_size19*20* PARAMETERS: file - Open file descriptor21*22* RETURN: File Size. On error, -1 (ACPI_UINT32_MAX)23*24* DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open.25* Does not disturb the current file pointer.26*27******************************************************************************/28u32 cm_get_file_size(ACPI_FILE file)29{30long file_size;31long current_offset;32acpi_status status;3334/* Save the current file pointer, seek to EOF to obtain file size */3536current_offset = ftell(file);37if (current_offset < 0) {38goto offset_error;39}4041status = fseek(file, 0, SEEK_END);42if (ACPI_FAILURE(status)) {43goto seek_error;44}4546file_size = ftell(file);47if (file_size < 0) {48goto offset_error;49}5051/* Restore original file pointer */5253status = fseek(file, current_offset, SEEK_SET);54if (ACPI_FAILURE(status)) {55goto seek_error;56}5758return ((u32)file_size);5960offset_error:61fprintf(stderr, "Could not get file offset\n");62return (ACPI_UINT32_MAX);6364seek_error:65fprintf(stderr, "Could not set file offset\n");66return (ACPI_UINT32_MAX);67}686970