WIP FPC-III support
[linux/fpc-iii.git] / tools / power / acpi / common / cmfsize.c
blobd1d18ff5c9114b182036881b8bc84d647e8a3cd0
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: cfsize - Common get file size function
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acapps.h"
14 #define _COMPONENT ACPI_TOOLS
15 ACPI_MODULE_NAME("cmfsize")
17 /*******************************************************************************
19 * FUNCTION: cm_get_file_size
21 * PARAMETERS: file - Open file descriptor
23 * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX)
25 * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open.
26 * Does not disturb the current file pointer.
28 ******************************************************************************/
29 u32 cm_get_file_size(ACPI_FILE file)
31 long file_size;
32 long current_offset;
33 acpi_status status;
35 /* Save the current file pointer, seek to EOF to obtain file size */
37 current_offset = ftell(file);
38 if (current_offset < 0) {
39 goto offset_error;
42 status = fseek(file, 0, SEEK_END);
43 if (ACPI_FAILURE(status)) {
44 goto seek_error;
47 file_size = ftell(file);
48 if (file_size < 0) {
49 goto offset_error;
52 /* Restore original file pointer */
54 status = fseek(file, current_offset, SEEK_SET);
55 if (ACPI_FAILURE(status)) {
56 goto seek_error;
59 return ((u32)file_size);
61 offset_error:
62 fprintf(stderr, "Could not get file offset\n");
63 return (ACPI_UINT32_MAX);
65 seek_error:
66 fprintf(stderr, "Could not set file offset\n");
67 return (ACPI_UINT32_MAX);