Share more duplicated functions
[reactos.git] / reactos / lib / string / strtoul.c
similarity index 91%
rename from reactos/lib/ntdll/stdlib/strtoul.c
rename to reactos/lib/string/strtoul.c
index cf28c14..9b7c712 100644 (file)
@@ -1,73 +1,73 @@
-/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
-#include <ntdll.h>
-
-
-/*
- * Convert a string to an unsigned long integer.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- *
- * @implemented
- */
-unsigned long
-strtoul(const char *nptr, char **endptr, int base)
-{
-  const char *s = nptr;
-  unsigned long acc;
-  int c;
-  unsigned long cutoff;
-  int neg = 0, any, cutlim;
-
-  /*
-   * See strtol for comments as to the logic used.
-   */
-  do {
-    c = *s++;
-  } while (isspace(c));
-  if (c == '-')
-  {
-    neg = 1;
-    c = *s++;
-  }
-  else if (c == '+')
-    c = *s++;
-  if ((base == 0 || base == 16) &&
-      c == '0' && (*s == 'x' || *s == 'X'))
-  {
-    c = s[1];
-    s += 2;
-    base = 16;
-  }
-  if (base == 0)
-    base = c == '0' ? 8 : 10;
-  cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
-  cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
-  for (acc = 0, any = 0;; c = *s++)
-  {
-    if (isdigit(c))
-      c -= '0';
-    else if (isalpha(c))
-      c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-    else
-      break;
-    if (c >= base)
-      break;
-    if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
-      any = -1;
-    else {
-      any = 1;
-      acc *= base;
-      acc += c;
-    }
-  }
-  if (any < 0)
-  {
-    acc = ULONG_MAX;
-  }
-  else if (neg)
-    acc = -acc;
-  if (endptr != 0)
-    *endptr = any ? (char *)s - 1 : (char *)nptr;
-  return acc;
-}
+#include <string.h>\r
+#include <limits.h>\r
+#include <ctype.h>\r
+\r
+/*\r
+ * Convert a string to an unsigned long integer.\r
+ *\r
+ * Ignores `locale' stuff.  Assumes that the upper and lower case\r
+ * alphabets and digits are each contiguous.\r
+ *\r
+ * @implemented\r
+ */\r
+unsigned long\r
+strtoul(const char *nptr, char **endptr, int base)\r
+{\r
+  const char *s = nptr;\r
+  unsigned long acc;\r
+  int c;\r
+  unsigned long cutoff;\r
+  int neg = 0, any, cutlim;\r
+\r
+  /*\r
+   * See strtol for comments as to the logic used.\r
+   */\r
+  do {\r
+    c = *s++;\r
+  } while (isspace(c));\r
+  if (c == '-')\r
+  {\r
+    neg = 1;\r
+    c = *s++;\r
+  }\r
+  else if (c == '+')\r
+    c = *s++;\r
+  if ((base == 0 || base == 16) &&\r
+      c == '0' && (*s == 'x' || *s == 'X'))\r
+  {\r
+    c = s[1];\r
+    s += 2;\r
+    base = 16;\r
+  }\r
+  if (base == 0)\r
+    base = c == '0' ? 8 : 10;\r
+  cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;\r
+  cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;\r
+  for (acc = 0, any = 0;; c = *s++)\r
+  {\r
+    if (isdigit(c))\r
+      c -= '0';\r
+    else if (isalpha(c))\r
+      c -= isupper(c) ? 'A' - 10 : 'a' - 10;\r
+    else\r
+      break;\r
+    if (c >= base)\r
+      break;\r
+    if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))\r
+      any = -1;\r
+    else {\r
+      any = 1;\r
+      acc *= base;\r
+      acc += c;\r
+    }\r
+  }\r
+  if (any < 0)\r
+  {\r
+    acc = ULONG_MAX;\r
+  }\r
+  else if (neg)\r
+    acc = -acc;\r
+  if (endptr != 0)\r
+    *endptr = any ? (char *)s - 1 : (char *)nptr;\r
+  return acc;\r
+}\r