[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / utilities / utclib.c
index 009332f..2a64185 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- * Module Name: cmclib - Local implementation of C library functions
+ * Module Name: utclib - ACPICA implementations of C library functions
  *
  *****************************************************************************/
 
  *
  *****************************************************************************/
 
+#define ACPI_CLIBRARY
 #include "acpi.h"
 #include "accommon.h"
 
 /*
- * These implementations of standard C Library routines can optionally be
- * used if a C library is not available. In general, they are less efficient
- * than an inline or assembly implementation
+ * This module contains implementations of the standard C library functions
+ * that are required by the ACPICA code at both application level and kernel
+ * level.
+ *
+ * The module is an optional feature that can be used if a local/system
+ * C library is not available. Some operating system kernels may not have
+ * an internal C library.
+ *
+ * In general, these functions are less efficient than an inline or assembly
+ * code implementation.
+ *
+ * These C functions and the associated prototypes are enabled by default
+ * unless the ACPI_USE_SYSTEM_CLIBRARY symbol is defined. This is usually
+ * automatically defined for the ACPICA applications such as iASL and
+ * AcpiExec, so that these user-level applications use the local C library
+ * instead of the functions in this module.
  */
 
-#define _COMPONENT          ACPI_UTILITIES
-        ACPI_MODULE_NAME    ("cmclib")
+/*******************************************************************************
+ *
+ * Functions implemented in this module:
+ *
+ * FUNCTION:    memcmp
+ * FUNCTION:    memcpy
+ * FUNCTION:    memset
+ * FUNCTION:    strlen
+ * FUNCTION:    strcpy
+ * FUNCTION:    strncpy
+ * FUNCTION:    strcmp
+ * FUNCTION:    strchr
+ * FUNCTION:    strncmp
+ * FUNCTION:    strcat
+ * FUNCTION:    strncat
+ * FUNCTION:    strstr
+ * FUNCTION:    strtoul
+ * FUNCTION:    toupper
+ * FUNCTION:    tolower
+ * FUNCTION:    is* functions
+ *
+ ******************************************************************************/
 
+#define _COMPONENT          ACPI_UTILITIES
+        ACPI_MODULE_NAME    ("utclib")
 
-#ifndef ACPI_USE_SYSTEM_CLIBRARY
 
-#define NEGATIVE    1
-#define POSITIVE    0
+#ifndef ACPI_USE_SYSTEM_CLIBRARY    /* Entire module */
 
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtMemcmp (memcmp)
+ * FUNCTION:    memcmp
  *
  * PARAMETERS:  Buffer1         - First Buffer
  *              Buffer2         - Second Buffer
  * DESCRIPTION: Compare two Buffers, with a maximum length
  *
  ******************************************************************************/
-
+#ifdef __REACTOS__
 int
-AcpiUtMemcmp (
-    const char              *Buffer1,
-    const char              *Buffer2,
+memcmp (
+    const void              *VBuffer1,
+    const void              *VBuffer2,
     ACPI_SIZE               Count)
+#else /* __REACTOS__ */
+int
+memcmp (
+    void                    *VBuffer1,
+    void                    *VBuffer2,
+    ACPI_SIZE               Count)
+#endif /* __REACTOS__ */
 {
+    char                    *Buffer1 = (char *) VBuffer1;
+    char                    *Buffer2 = (char *) VBuffer2;
+
 
     for ( ; Count-- && (*Buffer1 == *Buffer2); Buffer1++, Buffer2++)
     {
@@ -164,7 +208,7 @@ AcpiUtMemcmp (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtMemcpy (memcpy)
+ * FUNCTION:    memcpy
  *
  * PARAMETERS:  Dest        - Target of the copy
  *              Src         - Source buffer to copy
@@ -177,7 +221,7 @@ AcpiUtMemcmp (
  ******************************************************************************/
 
 void *
-AcpiUtMemcpy (
+memcpy (
     void                    *Dest,
     const void              *Src,
     ACPI_SIZE               Count)
@@ -200,7 +244,7 @@ AcpiUtMemcpy (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtMemset (memset)
+ * FUNCTION:    memset
  *
  * PARAMETERS:  Dest        - Buffer to set
  *              Value       - Value to set each byte of memory
@@ -213,9 +257,9 @@ AcpiUtMemcpy (
  ******************************************************************************/
 
 void *
-AcpiUtMemset (
+memset (
     void                    *Dest,
-    UINT8                   Value,
+    int                     Value,
     ACPI_SIZE               Count)
 {
     char                    *New = (char *) Dest;
@@ -234,7 +278,7 @@ AcpiUtMemset (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrlen (strlen)
+ * FUNCTION:    strlen
  *
  * PARAMETERS:  String              - Null terminated string
  *
@@ -246,7 +290,7 @@ AcpiUtMemset (
 
 
 ACPI_SIZE
-AcpiUtStrlen (
+strlen (
     const char              *String)
 {
     UINT32                  Length = 0;
@@ -266,7 +310,7 @@ AcpiUtStrlen (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrcpy (strcpy)
+ * FUNCTION:    strcpy
  *
  * PARAMETERS:  DstString       - Target of the copy
  *              SrcString       - The source string to copy
@@ -278,7 +322,7 @@ AcpiUtStrlen (
  ******************************************************************************/
 
 char *
-AcpiUtStrcpy (
+strcpy (
     char                    *DstString,
     const char              *SrcString)
 {
@@ -304,7 +348,7 @@ AcpiUtStrcpy (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrncpy (strncpy)
+ * FUNCTION:    strncpy
  *
  * PARAMETERS:  DstString       - Target of the copy
  *              SrcString       - The source string to copy
@@ -317,7 +361,7 @@ AcpiUtStrcpy (
  ******************************************************************************/
 
 char *
-AcpiUtStrncpy (
+strncpy (
     char                    *DstString,
     const char              *SrcString,
     ACPI_SIZE               Count)
@@ -347,7 +391,7 @@ AcpiUtStrncpy (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrcmp (strcmp)
+ * FUNCTION:    strcmp
  *
  * PARAMETERS:  String1         - First string
  *              String2         - Second string
@@ -359,7 +403,7 @@ AcpiUtStrncpy (
  ******************************************************************************/
 
 int
-AcpiUtStrcmp (
+strcmp (
     const char              *String1,
     const char              *String2)
 {
@@ -379,7 +423,7 @@ AcpiUtStrcmp (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrchr (strchr)
+ * FUNCTION:    strchr
  *
  * PARAMETERS:  String          - Search string
  *              ch              - character to search for
@@ -391,7 +435,7 @@ AcpiUtStrcmp (
  ******************************************************************************/
 
 char *
-AcpiUtStrchr (
+strchr (
     const char              *String,
     int                     ch)
 {
@@ -411,7 +455,7 @@ AcpiUtStrchr (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrncmp (strncmp)
+ * FUNCTION:    strncmp
  *
  * PARAMETERS:  String1         - First string
  *              String2         - Second string
@@ -424,7 +468,7 @@ AcpiUtStrchr (
  ******************************************************************************/
 
 int
-AcpiUtStrncmp (
+strncmp (
     const char              *String1,
     const char              *String2,
     ACPI_SIZE               Count)
@@ -446,7 +490,7 @@ AcpiUtStrncmp (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrcat (Strcat)
+ * FUNCTION:    strcat
  *
  * PARAMETERS:  DstString       - Target of the copy
  *              SrcString       - The source string to copy
@@ -458,7 +502,7 @@ AcpiUtStrncmp (
  ******************************************************************************/
 
 char *
-AcpiUtStrcat (
+strcat (
     char                    *DstString,
     const char              *SrcString)
 {
@@ -481,7 +525,7 @@ AcpiUtStrcat (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrncat (strncat)
+ * FUNCTION:    strncat
  *
  * PARAMETERS:  DstString       - Target of the copy
  *              SrcString       - The source string to copy
@@ -495,7 +539,7 @@ AcpiUtStrcat (
  ******************************************************************************/
 
 char *
-AcpiUtStrncat (
+strncat (
     char                    *DstString,
     const char              *SrcString,
     ACPI_SIZE               Count)
@@ -529,7 +573,7 @@ AcpiUtStrncat (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrstr (strstr)
+ * FUNCTION:    strstr
  *
  * PARAMETERS:  String1         - Target string
  *              String2         - Substring to search for
@@ -542,25 +586,40 @@ AcpiUtStrncat (
  *
  ******************************************************************************/
 
+#ifdef __REACTOS__
 char *
-AcpiUtStrstr (
+strstr (
+    const char              *String1,
+    const char              *String2)
+#else /* __REACTOS **/
+char *
+strstr (
     char                    *String1,
     char                    *String2)
+#endif /* __REACTOS__ */
 {
     UINT32                  Length;
 
 
-    Length = AcpiUtStrlen (String2);
+    Length = strlen (String2);
     if (!Length)
     {
+#ifdef __REACTOS__
+        return (char *)(String1);
+#else /* __REACTOS__ */
         return (String1);
+#endif /* __REACTOS__ */
     }
 
-    while (AcpiUtStrlen (String1) >= Length)
+    while (strlen (String1) >= Length)
     {
-        if (AcpiUtMemcmp (String1, String2, Length) == 0)
+        if (memcmp (String1, String2, Length) == 0)
         {
+#ifdef __REACTOS__
+            return (char *)(String1);
+#else /* __REACTOS__ */
             return (String1);
+#endif /* __REACTOS__ */
         }
         String1++;
     }
@@ -571,7 +630,7 @@ AcpiUtStrstr (
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtStrtoul (strtoul)
+ * FUNCTION:    strtoul
  *
  * PARAMETERS:  String          - Null terminated string
  *              Terminater      - Where a pointer to the terminating byte is
@@ -581,12 +640,12 @@ AcpiUtStrstr (
  * RETURN:      Converted value
  *
  * DESCRIPTION: Convert a string into a 32-bit unsigned value.
- *              Note: use AcpiUtStrtoul64 for 64-bit integers.
+ *              Note: use strtoul64 for 64-bit integers.
  *
  ******************************************************************************/
 
 UINT32
-AcpiUtStrtoul (
+strtoul (
     const char              *String,
     char                    **Terminator,
     UINT32                  Base)
@@ -605,7 +664,7 @@ AcpiUtStrtoul (
      * skip over any white space in the buffer:
      */
     StringStart = String;
-    while (ACPI_IS_SPACE (*String) || *String == '\t')
+    while (isspace (*String) || *String == '\t')
     {
         ++String;
     }
@@ -616,17 +675,17 @@ AcpiUtStrtoul (
      */
     if (*String == '-')
     {
-        sign = NEGATIVE;
+        sign = ACPI_SIGN_NEGATIVE;
         ++String;
     }
     else if (*String == '+')
     {
         ++String;
-        sign = POSITIVE;
+        sign = ACPI_SIGN_POSITIVE;
     }
     else
     {
-        sign = POSITIVE;
+        sign = ACPI_SIGN_POSITIVE;
     }
 
     /*
@@ -637,7 +696,7 @@ AcpiUtStrtoul (
     {
         if (*String == '0')
         {
-            if (AcpiUtToLower (*(++String)) == 'x')
+            if (tolower (*(++String)) == 'x')
             {
                 Base = 16;
                 ++String;
@@ -672,7 +731,7 @@ AcpiUtStrtoul (
 
     if (Base == 16 &&
         *String == '0' &&
-        AcpiUtToLower (*(++String)) == 'x')
+        tolower (*(++String)) == 'x')
     {
         String++;
     }
@@ -682,14 +741,14 @@ AcpiUtStrtoul (
      */
     while (*String)
     {
-        if (ACPI_IS_DIGIT (*String))
+        if (isdigit (*String))
         {
             index = (UINT32) ((UINT8) *String - '0');
         }
         else
         {
-            index = (UINT32) AcpiUtToUpper (*String);
-            if (ACPI_IS_UPPER (index))
+            index = (UINT32) toupper (*String);
+            if (isupper (index))
             {
                 index = index - 'A' + 10;
             }
@@ -749,7 +808,7 @@ done:
     /*
      * If a minus sign was present, then "the conversion is negated":
      */
-    if (sign == NEGATIVE)
+    if (sign == ACPI_SIGN_NEGATIVE)
     {
         ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
     }
@@ -760,7 +819,7 @@ done:
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtToUpper (TOUPPER)
+ * FUNCTION:    toupper
  *
  * PARAMETERS:  c           - Character to convert
  *
@@ -771,17 +830,17 @@ done:
  ******************************************************************************/
 
 int
-AcpiUtToUpper (
+toupper (
     int                     c)
 {
 
-    return (ACPI_IS_LOWER(c) ? ((c)-0x20) : (c));
+    return (islower(c) ? ((c)-0x20) : (c));
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    AcpiUtToLower (TOLOWER)
+ * FUNCTION:    tolower
  *
  * PARAMETERS:  c           - Character to convert
  *
@@ -792,23 +851,23 @@ AcpiUtToUpper (
  ******************************************************************************/
 
 int
-AcpiUtToLower (
+tolower (
     int                     c)
 {
 
-    return (ACPI_IS_UPPER(c) ? ((c)+0x20) : (c));
+    return (isupper(c) ? ((c)+0x20) : (c));
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    is* functions
+ * FUNCTION:    is* function array
  *
  * DESCRIPTION: is* functions use the ctype table below
  *
  ******************************************************************************/
 
-const UINT8 _acpi_ctype[257] = {
+const UINT8 AcpiGbl_Ctypes[257] = {
     _ACPI_CN,            /* 0x00     0 NUL */
     _ACPI_CN,            /* 0x01     1 SOH */
     _ACPI_CN,            /* 0x02     2 STX */