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>
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
)
35 /* Save the current file pointer, seek to EOF to obtain file size */
37 current_offset
= ftell(file
);
38 if (current_offset
< 0) {
42 status
= fseek(file
, 0, SEEK_END
);
43 if (ACPI_FAILURE(status
)) {
47 file_size
= ftell(file
);
52 /* Restore original file pointer */
54 status
= fseek(file
, current_offset
, SEEK_SET
);
55 if (ACPI_FAILURE(status
)) {
59 return ((u32
)file_size
);
62 fprintf(stderr
, "Could not get file offset\n");
63 return (ACPI_UINT32_MAX
);
66 fprintf(stderr
, "Could not set file offset\n");
67 return (ACPI_UINT32_MAX
);