ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

strtoul.c
Go to the documentation of this file.
00001 #include <precomp.h>
00002 #include <ctype.h>
00003 
00004 /*
00005  * Convert a string to an unsigned long integer.
00006  *
00007  * Ignores `locale' stuff.  Assumes that the upper and lower case
00008  * alphabets and digits are each contiguous.
00009  *
00010  * @implemented
00011  */
00012 unsigned long
00013 strtoul(const char *nptr, char **endptr, int base)
00014 {
00015   const char *s = nptr;
00016   unsigned long acc;
00017   int c;
00018   unsigned long cutoff;
00019   int neg = 0, any, cutlim;
00020 
00021   /*
00022    * See strtol for comments as to the logic used.
00023    */
00024   do {
00025     c = *s++;
00026   } while (isspace(c));
00027   if (c == '-')
00028   {
00029     neg = 1;
00030     c = *s++;
00031   }
00032   else if (c == '+')
00033     c = *s++;
00034   if ((base == 0 || base == 16) &&
00035       c == '0' && (*s == 'x' || *s == 'X'))
00036   {
00037     c = s[1];
00038     s += 2;
00039     base = 16;
00040   }
00041   if (base == 0)
00042     base = c == '0' ? 8 : 10;
00043   cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
00044   cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
00045   for (acc = 0, any = 0;; c = *s++)
00046   {
00047     if (isdigit(c))
00048       c -= '0';
00049     else if (isalpha(c))
00050       c -= isupper(c) ? 'A' - 10 : 'a' - 10;
00051     else
00052       break;
00053     if (c >= base)
00054       break;
00055     if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
00056       any = -1;
00057     else {
00058       any = 1;
00059       acc *= base;
00060       acc += c;
00061     }
00062   }
00063   if (any < 0)
00064   {
00065     acc = ULONG_MAX;
00066 #ifndef _LIBCNT_
00067     _set_errno(ERANGE);
00068 #endif
00069   }
00070   else if (neg)
00071     acc = 0-acc;
00072   if (endptr != 0)
00073     *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr);
00074   return acc;
00075 }

Generated on Sat May 26 2012 04:35:36 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.