~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/power/acpi/common/cmfsize.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2 /******************************************************************************
  3  *
  4  * Module Name: cmfsize - Common get file size function
  5  *
  6  * Copyright (C) 2000 - 2023, Intel Corp.
  7  *
  8  *****************************************************************************/
  9 
 10 #include <acpi/acpi.h>
 11 #include "accommon.h"
 12 #include "acapps.h"
 13 
 14 #define _COMPONENT          ACPI_TOOLS
 15 ACPI_MODULE_NAME("cmfsize")
 16 
 17 /*******************************************************************************
 18  *
 19  * FUNCTION:    cm_get_file_size
 20  *
 21  * PARAMETERS:  file                    - Open file descriptor
 22  *
 23  * RETURN:      File Size. On error, -1 (ACPI_UINT32_MAX)
 24  *
 25  * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open.
 26  *              Does not disturb the current file pointer.
 27  *
 28  ******************************************************************************/
 29 u32 cm_get_file_size(ACPI_FILE file)
 30 {
 31         long file_size;
 32         long current_offset;
 33         acpi_status status;
 34 
 35         /* Save the current file pointer, seek to EOF to obtain file size */
 36 
 37         current_offset = ftell(file);
 38         if (current_offset < 0) {
 39                 goto offset_error;
 40         }
 41 
 42         status = fseek(file, 0, SEEK_END);
 43         if (ACPI_FAILURE(status)) {
 44                 goto seek_error;
 45         }
 46 
 47         file_size = ftell(file);
 48         if (file_size < 0) {
 49                 goto offset_error;
 50         }
 51 
 52         /* Restore original file pointer */
 53 
 54         status = fseek(file, current_offset, SEEK_SET);
 55         if (ACPI_FAILURE(status)) {
 56                 goto seek_error;
 57         }
 58 
 59         return ((u32)file_size);
 60 
 61 offset_error:
 62         fprintf(stderr, "Could not get file offset\n");
 63         return (ACPI_UINT32_MAX);
 64 
 65 seek_error:
 66         fprintf(stderr, "Could not set file offset\n");
 67         return (ACPI_UINT32_MAX);
 68 }
 69 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php