ReactOS  0.4.14-dev-1115-gebeeb9d
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 146 of file utstrsuppt.c.

149 {
150  UINT64 AccumulatedValue = 0;
152 
153 
154  /* Convert each ASCII byte in the input string */
155 
156  while (*String)
157  {
158  /* Character must be ASCII 0-9, otherwise terminate with no error */
159 
160  if (!isdigit (*String))
161  {
162  break;
163  }
164 
165  /* Convert and insert this decimal digit into the accumulator */
166 
167  Status = AcpiUtInsertDigit (&AccumulatedValue, 10, *String);
168  if (ACPI_FAILURE (Status))
169  {
171  break;
172  }
173 
174  String++;
175  }
176 
177  /* Always return the value that has been accumulated */
178 
179  *ReturnValuePtr = AccumulatedValue;
180  return (Status);
181 }
#define AE_DECIMAL_OVERFLOW
Definition: acexcep.h:141
static WCHAR String[]
Definition: stringtable.c:55
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define isdigit(c)
Definition: acclib.h:68
Status
Definition: gdiplustypes.h:24
static ACPI_STATUS AcpiUtInsertDigit(UINT64 *AccumulatedValue, UINT32 Base, int AsciiDigit)
Definition: utstrsuppt.c:406
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiUtExplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtConvertHexString()

ACPI_STATUS AcpiUtConvertHexString ( char String,
UINT64 ReturnValuePtr 
)

Definition at line 202 of file utstrsuppt.c.

205 {
206  UINT64 AccumulatedValue = 0;
208 
209 
210  /* Convert each ASCII byte in the input string */
211 
212  while (*String)
213  {
214  /* Must be ASCII A-F, a-f, or 0-9, otherwise terminate with no error */
215 
216  if (!isxdigit (*String))
217  {
218  break;
219  }
220 
221  /* Convert and insert this hex digit into the accumulator */
222 
223  Status = AcpiUtInsertDigit (&AccumulatedValue, 16, *String);
224  if (ACPI_FAILURE (Status))
225  {
227  break;
228  }
229 
230  String++;
231  }
232 
233  /* Always return the value that has been accumulated */
234 
235  *ReturnValuePtr = AccumulatedValue;
236  return (Status);
237 }
static WCHAR String[]
Definition: stringtable.c:55
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_HEX_OVERFLOW
Definition: acexcep.h:140
Status
Definition: gdiplustypes.h:24
#define isxdigit(c)
Definition: acclib.h:70
static ACPI_STATUS AcpiUtInsertDigit(UINT64 *AccumulatedValue, UINT32 Base, int AsciiDigit)
Definition: utstrsuppt.c:406
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

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  /* Character must be ASCII 0-7, otherwise terminate with no error */
103 
104  if (!(ACPI_IS_OCTAL_DIGIT (*String)))
105  {
106  break;
107  }
108 
109  /* Convert and insert this octal digit into the accumulator */
110 
111  Status = AcpiUtInsertDigit (&AccumulatedValue, 8, *String);
112  if (ACPI_FAILURE (Status))
113  {
115  break;
116  }
117 
118  String++;
119  }
120 
121  /* Always return the value that has been accumulated */
122 
123  *ReturnValuePtr = AccumulatedValue;
124  return (Status);
125 }
#define AE_OCTAL_OVERFLOW
Definition: acexcep.h:142
static WCHAR String[]
Definition: stringtable.c:55
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
Status
Definition: gdiplustypes.h:24
#define ACPI_IS_OCTAL_DIGIT(d)
Definition: acmacros.h:501
static ACPI_STATUS AcpiUtInsertDigit(UINT64 *AccumulatedValue, UINT32 Base, int AsciiDigit)
Definition: utstrsuppt.c:406
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiUtStrtoul64().

◆ AcpiUtDetectHexPrefix()

BOOLEAN AcpiUtDetectHexPrefix ( char **  String)

Definition at line 311 of file utstrsuppt.c.

313 {
314  char *InitialPosition = *String;
315 
317  if (*String != InitialPosition)
318  {
319  return (TRUE); /* String is past leading 0x */
320  }
321 
322  return (FALSE); /* Not a hex string */
323 }
#define TRUE
Definition: types.h:120
void AcpiUtRemoveHexPrefix(char **String)
Definition: utstrsuppt.c:339
static WCHAR String[]
Definition: stringtable.c:55

Referenced by AcpiUtExplicitStrtoul64(), and AcpiUtStrtoul64().

◆ AcpiUtDetectOctalPrefix()

BOOLEAN AcpiUtDetectOctalPrefix ( char **  String)

Definition at line 364 of file utstrsuppt.c.

366 {
367 
368  if (**String == ACPI_ASCII_ZERO)
369  {
370  *String += 1; /* Go past the leading 0 */
371  return (TRUE);
372  }
373 
374  return (FALSE); /* Not an octal string */
375 }
#define TRUE
Definition: types.h:120
static WCHAR String[]
Definition: stringtable.c:55
#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 406 of file utstrsuppt.c.

410 {
412  UINT64 Product;
413 
414 
415  /* Make room in the accumulated value for the incoming digit */
416 
417  Status = AcpiUtStrtoulMultiply64 (*AccumulatedValue, Base, &Product);
418  if (ACPI_FAILURE (Status))
419  {
420  return (Status);
421  }
422 
423  /* Add in the new digit, and store the sum to the accumulated value */
424 
425  Status = AcpiUtStrtoulAdd64 (Product, AcpiUtAsciiCharToHex (AsciiDigit),
426  AccumulatedValue);
427 
428  return (Status);
429 }
UINT8 AcpiUtAsciiCharToHex(int HexChar)
Definition: uthex.c:135
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2374
static ACPI_STATUS AcpiUtStrtoulMultiply64(UINT64 Multiplicand, UINT32 Base, UINT64 *OutProduct)
Definition: utstrsuppt.c:449
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
Status
Definition: gdiplustypes.h:24
static ACPI_STATUS AcpiUtStrtoulAdd64(UINT64 Addend1, UINT32 Digit, UINT64 *OutSum)
Definition: utstrsuppt.c:511
unsigned long long UINT64

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

◆ AcpiUtRemoveHexPrefix()

void AcpiUtRemoveHexPrefix ( char **  String)

Definition at line 339 of file utstrsuppt.c.

341 {
342  if ((**String == ACPI_ASCII_ZERO) &&
343  (tolower ((int) *(*String + 1)) == 'x'))
344  {
345  *String += 2; /* Go past the leading 0x */
346  }
347 }
static WCHAR String[]
Definition: stringtable.c:55
#define ACPI_ASCII_ZERO
Definition: aclocal.h:1356
int tolower(int c)
Definition: utclib.c:902

Referenced by AcpiUtDetectHexPrefix(), and AcpiUtImplicitStrtoul64().

◆ AcpiUtRemoveLeadingZeros()

char AcpiUtRemoveLeadingZeros ( char **  String)

Definition at line 256 of file utstrsuppt.c.

258 {
259 
260  while (**String == ACPI_ASCII_ZERO)
261  {
262  *String += 1;
263  }
264 
265  return (**String);
266 }
static WCHAR String[]
Definition: stringtable.c:55
#define ACPI_ASCII_ZERO
Definition: aclocal.h:1356

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

◆ AcpiUtRemoveWhitespace()

char AcpiUtRemoveWhitespace ( char **  String)

Definition at line 285 of file utstrsuppt.c.

287 {
288 
289  while (isspace ((UINT8) **String))
290  {
291  *String += 1;
292  }
293 
294  return (**String);
295 }
#define isspace(c)
Definition: acclib.h:69
static WCHAR String[]
Definition: stringtable.c:55
unsigned char UINT8

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

◆ AcpiUtStrtoulAdd64()

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

Definition at line 511 of file utstrsuppt.c.

515 {
516  UINT64 Sum;
517 
518 
519  /* Check for 64-bit overflow before the actual addition */
520 
521  if ((Addend1 > 0) && (Digit > (ACPI_UINT64_MAX - Addend1)))
522  {
523  return (AE_NUMERIC_OVERFLOW);
524  }
525 
526  Sum = Addend1 + Digit;
527 
528  /* Check for 32-bit overflow if necessary */
529 
530  if ((AcpiGbl_IntegerBitWidth == 32) && (Sum > ACPI_UINT32_MAX))
531  {
532  return (AE_NUMERIC_OVERFLOW);
533  }
534 
535  *OutSum = Sum;
536  return (AE_OK);
537 }
#define AE_NUMERIC_OVERFLOW
Definition: acexcep.h:139
#define ACPI_UINT32_MAX
Definition: actypes.h:66
#define ACPI_UINT64_MAX
Definition: actypes.h:67
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiUtInsertDigit().

◆ AcpiUtStrtoulMultiply64()

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

Definition at line 449 of file utstrsuppt.c.

453 {
454  UINT64 Product;
455  UINT64 Quotient;
456 
457 
458  /* Exit if either operand is zero */
459 
460  *OutProduct = 0;
461  if (!Multiplicand || !Base)
462  {
463  return (AE_OK);
464  }
465 
466  /*
467  * Check for 64-bit overflow before the actual multiplication.
468  *
469  * Notes: 64-bit division is often not supported on 32-bit platforms
470  * (it requires a library function), Therefore ACPICA has a local
471  * 64-bit divide function. Also, Multiplier is currently only used
472  * as the radix (8/10/16), to the 64/32 divide will always work.
473  */
475  if (Multiplicand > Quotient)
476  {
477  return (AE_NUMERIC_OVERFLOW);
478  }
479 
480  Product = Multiplicand * Base;
481 
482  /* Check for 32-bit overflow if necessary */
483 
484  if ((AcpiGbl_IntegerBitWidth == 32) && (Product > ACPI_UINT32_MAX))
485  {
486  return (AE_NUMERIC_OVERFLOW);
487  }
488 
489  *OutProduct = Product;
490  return (AE_OK);
491 }
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2374
#define AE_NUMERIC_OVERFLOW
Definition: acexcep.h:139
smooth NULL
Definition: ftsmooth.c:416
ACPI_STATUS AcpiUtShortDivide(UINT64 InDividend, UINT32 Divisor, UINT64 *OutQuotient, UINT32 *OutRemainder)
Definition: utmath.c:337
#define ACPI_UINT32_MAX
Definition: actypes.h:66
#define ACPI_UINT64_MAX
Definition: actypes.h:67
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiUtInsertDigit().