^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: utprint - Formatted printing routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define _COMPONENT ACPI_UTILITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) ACPI_MODULE_NAME("utprint")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ACPI_FORMAT_SIGN 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ACPI_FORMAT_SIGN_PLUS 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ACPI_FORMAT_SIGN_PLUS_SPACE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ACPI_FORMAT_ZERO 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ACPI_FORMAT_LEFT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ACPI_FORMAT_UPPER 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ACPI_FORMAT_PREFIX 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static acpi_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) acpi_ut_bound_string_length(const char *string, acpi_size count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static char *acpi_ut_bound_string_output(char *string, const char *end, char c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static char *acpi_ut_format_number(char *string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) char *end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u64 number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u8 base, s32 width, s32 precision, u8 type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * FUNCTION: acpi_ut_bound_string_length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * PARAMETERS: string - String with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * count - Boundary of the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * RETURN: Length of the string. Less than or equal to Count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * DESCRIPTION: Calculate the length of a string with boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static acpi_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) acpi_ut_bound_string_length(const char *string, acpi_size count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) while (*string && count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) length++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) string++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * FUNCTION: acpi_ut_bound_string_output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * PARAMETERS: string - String with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * end - Boundary of the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * c - Character to be output to the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * RETURN: Updated position for next valid character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * DESCRIPTION: Output a character into a string with boundary check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static char *acpi_ut_bound_string_output(char *string, const char *end, char c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (string < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *string = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ++string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return (string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * FUNCTION: acpi_ut_put_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * PARAMETERS: string - Buffer to hold reverse-ordered string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * number - Integer to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * base - Base of the integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * upper - Whether or not using upper cased digits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * RETURN: Updated position for next valid character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * DESCRIPTION: Convert an integer into a string, note that, the string holds a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * reversed ordered number without the trailing zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const char *digits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u64 digit_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pos = string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) digits = upper ? acpi_gbl_upper_hex_digits : acpi_gbl_lower_hex_digits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (number == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *(pos++) = '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) while (number) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) (void)acpi_ut_divide(number, base, &number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) &digit_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *(pos++) = digits[digit_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* *(Pos++) = '0'; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return (pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * FUNCTION: acpi_ut_scan_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * PARAMETERS: string - String buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * number_ptr - Where the number is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * RETURN: Updated position for next valid character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * DESCRIPTION: Scan a string for a decimal integer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) const char *acpi_ut_scan_number(const char *string, u64 *number_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u64 number = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) while (isdigit((int)*string)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) acpi_ut_short_multiply(number, 10, &number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) number += *(string++) - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) *number_ptr = number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return (string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * FUNCTION: acpi_ut_print_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * PARAMETERS: string - String buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * number - The number to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * RETURN: Updated position for next valid character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * DESCRIPTION: Print a decimal integer into a string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) const char *acpi_ut_print_number(char *string, u64 number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) char ascii_string[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) const char *pos1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) char *pos2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) pos1 = acpi_ut_put_number(ascii_string, number, 10, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pos2 = string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) while (pos1 != ascii_string) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *(pos2++) = *(--pos1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *pos2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return (string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * FUNCTION: acpi_ut_format_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * PARAMETERS: string - String buffer with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * end - Boundary of the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * number - The number to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * base - Base of the integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * width - Field width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * precision - Precision of the integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * type - Special printing flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * RETURN: Updated position for next valid character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * DESCRIPTION: Print an integer into a string with any base and any precision.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static char *acpi_ut_format_number(char *string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) char *end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u64 number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u8 base, s32 width, s32 precision, u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) char sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) char zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u8 need_prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 upper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) s32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) char reversed_string[66];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Parameter validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (base < 2 || base > 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return (NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (type & ACPI_FORMAT_LEFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) type &= ~ACPI_FORMAT_ZERO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) need_prefix = ((type & ACPI_FORMAT_PREFIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) && base != 10) ? TRUE : FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) upper = (type & ACPI_FORMAT_UPPER) ? TRUE : FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) zero = (type & ACPI_FORMAT_ZERO) ? '0' : ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* Calculate size according to sign and prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) sign = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (type & ACPI_FORMAT_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if ((s64)number < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sign = '-';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) number = -(s64)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) width--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } else if (type & ACPI_FORMAT_SIGN_PLUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) sign = '+';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) width--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) } else if (type & ACPI_FORMAT_SIGN_PLUS_SPACE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) sign = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) width--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (need_prefix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) width--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (base == 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) width--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Generate full string in reverse order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) pos = acpi_ut_put_number(reversed_string, number, base, upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) i = (s32)ACPI_PTR_DIFF(pos, reversed_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Printing 100 using %2d gives "100", not "00" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (i > precision) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) precision = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) width -= precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* Output the string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (!(type & (ACPI_FORMAT_ZERO | ACPI_FORMAT_LEFT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) while (--width >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) string = acpi_ut_bound_string_output(string, end, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (sign) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) string = acpi_ut_bound_string_output(string, end, sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (need_prefix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) string = acpi_ut_bound_string_output(string, end, '0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (base == 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) string =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) acpi_ut_bound_string_output(string, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) upper ? 'X' : 'x');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (!(type & ACPI_FORMAT_LEFT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) while (--width >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) string = acpi_ut_bound_string_output(string, end, zero);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) while (i <= --precision) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) string = acpi_ut_bound_string_output(string, end, '0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) while (--i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) string = acpi_ut_bound_string_output(string, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) reversed_string[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) while (--width >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) string = acpi_ut_bound_string_output(string, end, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return (string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * FUNCTION: vsnprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * PARAMETERS: string - String with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * size - Boundary of the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * format - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * args - Argument list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * DESCRIPTION: Formatted output to a string using argument list pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int vsnprintf(char *string, acpi_size size, const char *format, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) u8 base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) s32 width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) s32 precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) char qualifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) u64 number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) const char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) const void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) s32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) pos = string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (size != ACPI_UINT32_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) end = string + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) end = ACPI_CAST_PTR(char, ACPI_UINT32_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) for (; *format; ++format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (*format != '%') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) pos = acpi_ut_bound_string_output(pos, end, *format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) base = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Process sign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (*format == '#') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) type |= ACPI_FORMAT_PREFIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) } else if (*format == '0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) type |= ACPI_FORMAT_ZERO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) } else if (*format == '+') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) type |= ACPI_FORMAT_SIGN_PLUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) } else if (*format == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) type |= ACPI_FORMAT_SIGN_PLUS_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) } else if (*format == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) type |= ACPI_FORMAT_LEFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) } while (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* Process width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) width = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (isdigit((int)*format)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) format = acpi_ut_scan_number(format, &number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) width = (s32)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) } else if (*format == '*') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) width = va_arg(args, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (width < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) width = -width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) type |= ACPI_FORMAT_LEFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* Process precision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) precision = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (*format == '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (isdigit((int)*format)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) format = acpi_ut_scan_number(format, &number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) precision = (s32)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) } else if (*format == '*') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) precision = va_arg(args, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (precision < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) precision = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* Process qualifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) qualifier = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (*format == 'h' || *format == 'l' || *format == 'L') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) qualifier = *format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (qualifier == 'l' && *format == 'l') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) qualifier = 'L';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ++format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) switch (*format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) case '%':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) pos = acpi_ut_bound_string_output(pos, end, '%');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!(type & ACPI_FORMAT_LEFT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) while (--width > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) acpi_ut_bound_string_output(pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) c = (char)va_arg(args, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) pos = acpi_ut_bound_string_output(pos, end, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) while (--width > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) acpi_ut_bound_string_output(pos, end, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) s = va_arg(args, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (!s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) s = "<NULL>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) length = (s32)acpi_ut_bound_string_length(s, precision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (!(type & ACPI_FORMAT_LEFT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) while (length < width--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) acpi_ut_bound_string_output(pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) for (i = 0; i < length; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) pos = acpi_ut_bound_string_output(pos, end, *s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ++s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) while (length < width--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) acpi_ut_bound_string_output(pos, end, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) base = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) case 'X':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) type |= ACPI_FORMAT_UPPER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* FALLTHROUGH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) case 'x':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) base = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) case 'i':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) type |= ACPI_FORMAT_SIGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) case 'u':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) case 'p':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (width == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) width = 2 * sizeof(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) type |= ACPI_FORMAT_ZERO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) p = va_arg(args, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) acpi_ut_format_number(pos, end, ACPI_TO_INTEGER(p),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 16, width, precision, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) pos = acpi_ut_bound_string_output(pos, end, '%');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (*format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) pos =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) acpi_ut_bound_string_output(pos, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) *format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) --format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (qualifier == 'L') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) number = va_arg(args, u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (type & ACPI_FORMAT_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) number = (s64)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) } else if (qualifier == 'l') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) number = va_arg(args, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (type & ACPI_FORMAT_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) number = (s32)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) } else if (qualifier == 'h') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) number = (u16)va_arg(args, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (type & ACPI_FORMAT_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) number = (s16)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) number = va_arg(args, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (type & ACPI_FORMAT_SIGN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) number = (signed int)number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) pos = acpi_ut_format_number(pos, end, number, base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) width, precision, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (pos < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) *pos = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) end[-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return ((int)ACPI_PTR_DIFF(pos, string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * FUNCTION: snprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * PARAMETERS: string - String with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * size - Boundary of the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * Format, ... - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * DESCRIPTION: Formatted output to a string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int snprintf(char *string, acpi_size size, const char *format, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) va_start(args, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) length = vsnprintf(string, size, format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * FUNCTION: sprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * PARAMETERS: string - String with boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * Format, ... - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * DESCRIPTION: Formatted output to a string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) int sprintf(char *string, const char *format, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) va_start(args, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) length = vsnprintf(string, ACPI_UINT32_MAX, format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) #ifdef ACPI_APPLICATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * FUNCTION: vprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * PARAMETERS: format - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * args - Argument list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * DESCRIPTION: Formatted output to stdout using argument list pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) int vprintf(const char *format, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) flags = acpi_os_acquire_lock(acpi_gbl_print_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) length = vsnprintf(acpi_gbl_print_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) sizeof(acpi_gbl_print_buffer), format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) (void)fwrite(acpi_gbl_print_buffer, length, 1, ACPI_FILE_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) acpi_os_release_lock(acpi_gbl_print_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * FUNCTION: printf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * PARAMETERS: Format, ... - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * DESCRIPTION: Formatted output to stdout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) int printf(const char *format, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) va_start(args, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) length = vprintf(format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * FUNCTION: vfprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * PARAMETERS: file - File descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * format - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * args - Argument list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * DESCRIPTION: Formatted output to a file using argument list pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int vfprintf(FILE * file, const char *format, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) flags = acpi_os_acquire_lock(acpi_gbl_print_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) length = vsnprintf(acpi_gbl_print_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) sizeof(acpi_gbl_print_buffer), format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) (void)fwrite(acpi_gbl_print_buffer, length, 1, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) acpi_os_release_lock(acpi_gbl_print_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * FUNCTION: fprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * PARAMETERS: file - File descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * Format, ... - Standard printf format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * RETURN: Number of bytes actually written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * DESCRIPTION: Formatted output to a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) int fprintf(FILE * file, const char *format, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) va_start(args, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) length = vfprintf(file, format, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) return (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) #endif