ReactOS 0.4.15-dev-8191-gbc6c731
utstrsuppt.c File Reference
#include "acpi.h"
#include "accommon.h"
Include dependency graph for utstrsuppt.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_UTILITIES
 

Functions

static ACPI_STATUS AcpiUtInsertDigit (UINT64 *AccumulatedValue, UINT32 Base, int AsciiDigit)
 
static ACPI_STATUS AcpiUtStrtoulMultiply64 (UINT64 Multiplicand, UINT32 Base, UINT64 *OutProduct)
 
static ACPI_STATUS AcpiUtStrtoulAdd64 (UINT64 Addend1, UINT32 Digit, UINT64 *OutSum)
 
ACPI_STATUS AcpiUtConvertOctalString (char *String, UINT64 *ReturnValuePtr)
 
ACPI_STATUS AcpiUtConvertDecimalString (char *String, UINT64 *ReturnValuePtr)
 
ACPI_STATUS AcpiUtConvertHexString (char *String, UINT64 *ReturnValuePtr)
 
char AcpiUtRemoveLeadingZeros (char **String)
 
char AcpiUtRemoveWhitespace (char **String)
 
BOOLEAN AcpiUtDetectHexPrefix (char **String)
 
void AcpiUtRemoveHexPrefix (char **String)
 
BOOLEAN AcpiUtDetectOctalPrefix (char **String)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_UTILITIES

Definition at line 47 of file utstrsuppt.c.

Function Documentation

◆ AcpiUtConvertDecimalString()

ACPI_STATUS AcpiUtConvertDecimalString ( char String,
UINT64 ReturnValuePtr 
)

Definition at line 152 of file utstrsuppt.c.

155{
156 UINT64 AccumulatedValue = 0;
158
159
160 /* Convert each ASCII byte in the input string */
161
162 while (*String)
163 {
164 /*
165 * Character must be ASCII 0-9, otherwise:
166 * 1) Runtime: terminate with no error, per the ACPI spec
167 * 2) Compiler: return an error
168 */
169 if (!isdigit ((int) *String))
170 {
171#ifdef ACPI_ASL_COMPILER
173#endif
174 break;
175 }
176
177 /* Convert and insert this decimal digit into the accumulator */
178
179 Status = AcpiUtInsertDigit (&AccumulatedValue, 10, *String);
180 if (ACPI_FAILURE (Status))
181 {
183 break;
184 }
185
186 String++;
187 }
188
189 /* Always return the value that has been accumulated */
190
191 *ReturnValuePtr = AccumulatedValue;
192 return (Status);
193}
unsigned long long UINT64
#define isdigit(c)
Definition: acclib.h:68
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_DECIMAL_OVERFLOW
Definition: acexcep.h:141
#define AE_BAD_DECIMAL_CONSTANT
Definition: acexcep.h:157
#define AE_OK
Definition: acexcep.h:97
UINT32 ACPI_STATUS
Definition: actypes.h:460
Status
Definition: gdiplustypes.h:25
static ACPI_STATUS AcpiUtInsertDigit(UINT64 *AccumulatedValue, UINT32 Base, int AsciiDigit)
Definition: utstrsuppt.c:424
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by AcpiUtExplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtConvertHexString()

ACPI_STATUS AcpiUtConvertHexString ( char String,
UINT64 ReturnValuePtr 
)

Definition at line 214 of file utstrsuppt.c.

217{
218 UINT64 AccumulatedValue = 0;
220
221
222 /* Convert each ASCII byte in the input string */
223
224 while (*String)
225 {
226 /*
227 * Character must be ASCII A-F, a-f, or 0-9, otherwise:
228 * 1) Runtime: terminate with no error, per the ACPI spec
229 * 2) Compiler: return an error
230 */
231 if (!isxdigit ((int) *String))
232 {
233#ifdef ACPI_ASL_COMPILER
235#endif
236 break;
237 }
238
239 /* Convert and insert this hex digit into the accumulator */
240
241 Status = AcpiUtInsertDigit (&AccumulatedValue, 16, *String);
242 if (ACPI_FAILURE (Status))
243 {
245 break;
246 }
247
248 String++;
249 }
250
251 /* Always return the value that has been accumulated */
252
253 *ReturnValuePtr = AccumulatedValue;
254 return (Status);
255}
#define isxdigit(c)
Definition: acclib.h:70
#define AE_BAD_HEX_CONSTANT
Definition: acexcep.h:155
#define AE_HEX_OVERFLOW
Definition: acexcep.h:140

Referenced by AcpiUtExplicitStrtoul64(), AcpiUtImplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtConvertOctalString()

ACPI_STATUS AcpiUtConvertOctalString ( char String,
UINT64 ReturnValuePtr 
)

Definition at line 90 of file utstrsuppt.c.

93{
94 UINT64 AccumulatedValue = 0;
96
97
98 /* Convert each ASCII byte in the input string */
99
100 while (*String)
101 {
102 /*
103 * Character must be ASCII 0-7, otherwise:
104 * 1) Runtime: terminate with no error, per the ACPI spec
105 * 2) Compiler: return an error
106 */
107 if (!(ACPI_IS_OCTAL_DIGIT (*String)))
108 {
109#ifdef ACPI_ASL_COMPILER
111#endif
112 break;
113 }
114
115 /* Convert and insert this octal digit into the accumulator */
116
117 Status = AcpiUtInsertDigit (&AccumulatedValue, 8, *String);
118 if (ACPI_FAILURE (Status))
119 {
121 break;
122 }
123
124 String++;
125 }
126
127 /* Always return the value that has been accumulated */
128
129 *ReturnValuePtr = AccumulatedValue;
130 return (Status);
131}
#define AE_BAD_OCTAL_CONSTANT
Definition: acexcep.h:156
#define AE_OCTAL_OVERFLOW
Definition: acexcep.h:142
#define ACPI_IS_OCTAL_DIGIT(d)
Definition: acmacros.h:501

Referenced by AcpiUtStrtoul64().

◆ AcpiUtDetectHexPrefix()

BOOLEAN AcpiUtDetectHexPrefix ( char **  String)

Definition at line 329 of file utstrsuppt.c.

331{
332 char *InitialPosition = *String;
333
335 if (*String != InitialPosition)
336 {
337 return (TRUE); /* String is past leading 0x */
338 }
339
340 return (FALSE); /* Not a hex string */
341}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void AcpiUtRemoveHexPrefix(char **String)
Definition: utstrsuppt.c:357

Referenced by AcpiUtExplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtDetectOctalPrefix()

BOOLEAN AcpiUtDetectOctalPrefix ( char **  String)

Definition at line 382 of file utstrsuppt.c.

384{
385
386 if (**String == ACPI_ASCII_ZERO)
387 {
388 *String += 1; /* Go past the leading 0 */
389 return (TRUE);
390 }
391
392 return (FALSE); /* Not an octal string */
393}
#define ACPI_ASCII_ZERO
Definition: aclocal.h:1356

Referenced by AcpiUtStrtoul64().

◆ AcpiUtInsertDigit()

static ACPI_STATUS AcpiUtInsertDigit ( UINT64 AccumulatedValue,
UINT32  Base,
int  AsciiDigit 
)
static

Definition at line 424 of file utstrsuppt.c.

428{
430 UINT64 Product;
431
432
433 /* Make room in the accumulated value for the incoming digit */
434
435 Status = AcpiUtStrtoulMultiply64 (*AccumulatedValue, Base, &Product);
436 if (ACPI_FAILURE (Status))
437 {
438 return (Status);
439 }
440
441 /* Add in the new digit, and store the sum to the accumulated value */
442
443 Status = AcpiUtStrtoulAdd64 (Product, AcpiUtAsciiCharToHex (AsciiDigit),
444 AccumulatedValue);
445
446 return (Status);
447}
UINT8 AcpiUtAsciiCharToHex(int HexChar)
Definition: uthex.c:135
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2439
static ACPI_STATUS AcpiUtStrtoulAdd64(UINT64 Addend1, UINT32 Digit, UINT64 *OutSum)
Definition: utstrsuppt.c:529
static ACPI_STATUS AcpiUtStrtoulMultiply64(UINT64 Multiplicand, UINT32 Base, UINT64 *OutProduct)
Definition: utstrsuppt.c:467

Referenced by AcpiUtConvertDecimalString(), AcpiUtConvertHexString(), and AcpiUtConvertOctalString().

◆ AcpiUtRemoveHexPrefix()

void AcpiUtRemoveHexPrefix ( char **  String)

Definition at line 357 of file utstrsuppt.c.

359{
360 if ((**String == ACPI_ASCII_ZERO) &&
361 (tolower ((int) *(*String + 1)) == 'x'))
362 {
363 *String += 2; /* Go past the leading 0x */
364 }
365}
int tolower(int c)
Definition: utclib.c:902

Referenced by AcpiUtDetectHexPrefix(), and AcpiUtImplicitStrtoul64().

◆ AcpiUtRemoveLeadingZeros()

char AcpiUtRemoveLeadingZeros ( char **  String)

Definition at line 274 of file utstrsuppt.c.

276{
277
278 while (**String == ACPI_ASCII_ZERO)
279 {
280 *String += 1;
281 }
282
283 return (**String);
284}

Referenced by AcpiUtExplicitStrtoul64(), AcpiUtImplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtRemoveWhitespace()

char AcpiUtRemoveWhitespace ( char **  String)

Definition at line 303 of file utstrsuppt.c.

305{
306
307 while (isspace ((UINT8) **String))
308 {
309 *String += 1;
310 }
311
312 return (**String);
313}
unsigned char UINT8
#define isspace(c)
Definition: acclib.h:69

Referenced by AcpiUtExplicitStrtoul64(), AcpiUtImplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtStrtoulAdd64()

static ACPI_STATUS AcpiUtStrtoulAdd64 ( UINT64  Addend1,
UINT32  Digit,
UINT64 OutSum 
)
static

Definition at line 529 of file utstrsuppt.c.

533{
534 UINT64 Sum;
535
536
537 /* Check for 64-bit overflow before the actual addition */
538
539 if ((Addend1 > 0) && (Digit > (ACPI_UINT64_MAX - Addend1)))
540 {
541 return (AE_NUMERIC_OVERFLOW);
542 }
543
544 Sum = Addend1 + Digit;
545
546 /* Check for 32-bit overflow if necessary */
547
548 if ((AcpiGbl_IntegerBitWidth == 32) && (Sum > ACPI_UINT32_MAX))
549 {
550 return (AE_NUMERIC_OVERFLOW);
551 }
552
553 *OutSum = Sum;
554 return (AE_OK);
555}
#define AE_NUMERIC_OVERFLOW
Definition: acexcep.h:139
#define ACPI_UINT64_MAX
Definition: actypes.h:67
#define ACPI_UINT32_MAX
Definition: actypes.h:66

Referenced by AcpiUtInsertDigit().

◆ AcpiUtStrtoulMultiply64()

static ACPI_STATUS AcpiUtStrtoulMultiply64 ( UINT64  Multiplicand,
UINT32  Base,
UINT64 OutProduct 
)
static

Definition at line 467 of file utstrsuppt.c.

471{
472 UINT64 Product;
473 UINT64 Quotient;
474
475
476 /* Exit if either operand is zero */
477
478 *OutProduct = 0;
479 if (!Multiplicand || !Base)
480 {
481 return (AE_OK);
482 }
483
484 /*
485 * Check for 64-bit overflow before the actual multiplication.
486 *
487 * Notes: 64-bit division is often not supported on 32-bit platforms
488 * (it requires a library function), Therefore ACPICA has a local
489 * 64-bit divide function. Also, Multiplier is currently only used
490 * as the radix (8/10/16), to the 64/32 divide will always work.
491 */
493 if (Multiplicand > Quotient)
494 {
495 return (AE_NUMERIC_OVERFLOW);
496 }
497
498 Product = Multiplicand * Base;
499
500 /* Check for 32-bit overflow if necessary */
501
502 if ((AcpiGbl_IntegerBitWidth == 32) && (Product > ACPI_UINT32_MAX))
503 {
504 return (AE_NUMERIC_OVERFLOW);
505 }
506
507 *OutProduct = Product;
508 return (AE_OK);
509}
ACPI_STATUS AcpiUtShortDivide(UINT64 InDividend, UINT32 Divisor, UINT64 *OutQuotient, UINT32 *OutRemainder)
Definition: utmath.c:337
#define NULL
Definition: types.h:112

Referenced by AcpiUtInsertDigit().