int AcpiUtToLower ( int c) { return (ACPI_IS_UPPER(c) ? ((c)+0x20) : (c)); }
ACPI_STATUS AcpiUtStrtoul64 ( char *String, UINT32 Base, ACPI_INTEGER *RetInteger) { UINT32 Index; ACPI_INTEGER ReturnValue = 0; ACPI_STATUS Status = AE_OK; ACPI_INTEGER Dividend; ACPI_INTEGER Quotient; *RetInteger = 0; switch (Base) { case 0: case 8: case 10: case 16: break; default: /* * The specified Base parameter is not in the domain of * this function: */ return (AE_BAD_PARAMETER); } /* * skip over any white space in the buffer: */ while (ACPI_IS_SPACE (*String) || *String == '\t') { ++String; } /* * If the input parameter Base is zero, then we need to * determine if it is octal, decimal, or hexadecimal: */ if (Base == 0) { if (*String == '0') { if (ACPI_TOLOWER (*(++String)) == 'x') { Base = 16; ++String; } else { Base = 8; } } else { Base = 10; } } /* * For octal and hexadecimal bases, skip over the leading * 0 or 0x, if they are present. */ if (Base == 8 && *String == '0') { String++; } if (Base == 16 && *String == '0' && ACPI_TOLOWER (*(++String)) == 'x') { String++; } /* Main loop: convert the string to an unsigned long */ while (*String) { if (ACPI_IS_DIGIT (*String)) { Index = ((UINT8) *String) - '0'; } else { Index = (UINT8) ACPI_TOUPPER (*String); if (ACPI_IS_UPPER ((char) Index)) { Index = Index - 'A' + 10; } else { goto ErrorExit; } } if (Index >= Base) { goto ErrorExit; } /* Check to see if value is out of range: */ Dividend = ACPI_INTEGER_MAX - (ACPI_INTEGER) Index; (void) AcpiUtShortDivide (&Dividend, Base, &Quotient, NULL); if (ReturnValue > Quotient) { goto ErrorExit; } ReturnValue *= Base; ReturnValue += Index; ++String; } *RetInteger = ReturnValue; return (Status); ErrorExit: switch (Base) { case 8: Status = AE_BAD_OCTAL_CONSTANT; break; case 10: Status = AE_BAD_DECIMAL_CONSTANT; break; case 16: Status = AE_BAD_HEX_CONSTANT; break; default: /* Base validated above */ break; } return (Status); }
UINT32 AcpiUtStrtoul ( const char *String, char **Terminator, UINT32 Base) { UINT32 converted = 0; UINT32 index; UINT32 sign; const char *StringStart; UINT32 ReturnValue = 0; ACPI_STATUS Status = AE_OK; /* * Save the value of the pointer to the buffer's first * character, save the current errno value, and then * skip over any white space in the buffer: */ StringStart = String; while (ACPI_IS_SPACE (*String) || *String == '\t') { ++String; } /* * The buffer may contain an optional plus or minus sign. * If it does, then skip over it but remember what is was: */ if (*String == '-') { sign = NEGATIVE; ++String; } else if (*String == '+') { ++String; sign = POSITIVE; } else { sign = POSITIVE; } /* * If the input parameter Base is zero, then we need to * determine if it is octal, decimal, or hexadecimal: */ if (Base == 0) { if (*String == '0') { if (AcpiUtToLower (*(++String)) == 'x') { Base = 16; ++String; } else { Base = 8; } } else { Base = 10; } } else if (Base < 2 || Base > 36) { /* * The specified Base parameter is not in the domain of * this function: */ goto done; } /* * For octal and hexadecimal bases, skip over the leading * 0 or 0x, if they are present. */ if (Base == 8 && *String == '0') { String++; } if (Base == 16 && *String == '0' && AcpiUtToLower (*(++String)) == 'x') { String++; } /* * Main loop: convert the string to an unsigned long: */ while (*String) { if (ACPI_IS_DIGIT (*String)) { index = (UINT32) ((UINT8) *String - '0'); } else { index = (UINT32) AcpiUtToUpper (*String); if (ACPI_IS_UPPER (index)) { index = index - 'A' + 10; } else { goto done; } } if (index >= Base) { goto done; } /* * Check to see if value is out of range: */ if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) / (UINT32) Base)) { Status = AE_ERROR; ReturnValue = 0; /* reset */ } else { ReturnValue *= Base; ReturnValue += index; converted = 1; } ++String; } done: /* * If appropriate, update the caller's pointer to the next * unconverted character in the buffer. */ if (Terminator) { if (converted == 0 && ReturnValue == 0 && String != NULL) { *Terminator = (char *) StringStart; } else { *Terminator = (char *) String; } } if (Status == AE_ERROR) { ReturnValue = ACPI_UINT32_MAX; } /* * If a minus sign was present, then "the conversion is negated": */ if (sign == NEGATIVE) { ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1; } return (ReturnValue); }
acpi_status acpi_ut_strtoul64 ( char *string, u32 base, acpi_integer *ret_integer) { u32 this_digit; acpi_integer return_value = 0; acpi_integer quotient; ACPI_FUNCTION_TRACE ("ut_stroul64"); switch (base) { case ACPI_ANY_BASE: case 10: case 16: break; default: /* Invalid Base */ return_ACPI_STATUS (AE_BAD_PARAMETER); } /* Skip over any white space in the buffer */ while (ACPI_IS_SPACE (*string) || *string == '\t') { ++string; } /* * If the input parameter Base is zero, then we need to * determine if it is decimal or hexadecimal: */ if (base == 0) { if ((*string == '0') && (ACPI_TOLOWER (*(++string)) == 'x')) { base = 16; ++string; } else { base = 10; } } /* * For hexadecimal base, skip over the leading * 0 or 0x, if they are present. */ if (base == 16 && *string == '0' && ACPI_TOLOWER (*(++string)) == 'x') { string++; } /* Any string left? */ if (!(*string)) { goto error_exit; } /* Main loop: convert the string to a 64-bit integer */ while (*string) { if (ACPI_IS_DIGIT (*string)) { /* Convert ASCII 0-9 to Decimal value */ this_digit = ((u8) *string) - '0'; } else { this_digit = (u8) ACPI_TOUPPER (*string); if (ACPI_IS_UPPER ((char) this_digit)) { /* Convert ASCII Hex char to value */ this_digit = this_digit - 'A' + 10; } else { goto error_exit; } } /* Check to see if digit is out of range */ if (this_digit >= base) { goto error_exit; } /* Divide the digit into the correct position */ (void) acpi_ut_short_divide ((ACPI_INTEGER_MAX - (acpi_integer) this_digit), base, "ient, NULL); if (return_value > quotient) { goto error_exit; } return_value *= base; return_value += this_digit; ++string; } *ret_integer = return_value; return_ACPI_STATUS (AE_OK); error_exit: /* Base was set/validated above */ if (base == 10) { return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT); } else { return_ACPI_STATUS (AE_BAD_HEX_CONSTANT); } }