Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // string.c
  4. //
  5. // This file contains most commonly used string operation. ALl the setup project should link here
  6. // or add the common utility here to avoid duplicating code everywhere or using CRT runtime.
  7. //
  8. // Created 4\15\997 inateeg
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////////////////////////
  11. #include <windows.h>
  12. #include "sdsutils.h"
  13. //=================================================================================================
  14. //
  15. // copied from msdev\crt\src\atox.c
  16. //
  17. // long AtoL(char *nptr) - Convert string to long
  18. //
  19. // Purpose:
  20. // Converts ASCII string pointed to by nptr to binary.
  21. // Overflow is not detected.
  22. //
  23. // Entry:
  24. // nptr = ptr to string to convert
  25. //
  26. // Exit:
  27. // return long int value of the string
  28. //
  29. // Exceptions:
  30. // None - overflow is not detected.
  31. //
  32. //=================================================================================================
  33. long AtoL(const char *nptr)
  34. {
  35. int c; /* current char */
  36. long total; /* current total */
  37. int sign; /* if '-', then negative, otherwise positive */
  38. // NOTE: no need to worry about DBCS chars here because IsSpace(c), IsDigit(c),
  39. // '+' and '-' are "pure" ASCII chars, i.e., they are neither DBCS Leading nor
  40. // DBCS Trailing bytes -- pritvi
  41. /* skip whitespace */
  42. while ( IsSpace((int)(unsigned char)*nptr) )
  43. ++nptr;
  44. c = (int)(unsigned char)*nptr++;
  45. sign = c; /* save sign indication */
  46. if (c == '-' || c == '+')
  47. c = (int)(unsigned char)*nptr++; /* skip sign */
  48. total = 0;
  49. while (IsDigit(c)) {
  50. total = 10 * total + (c - '0'); /* accumulate digit */
  51. c = (int)(unsigned char)*nptr++; /* get next char */
  52. }
  53. if (sign == '-')
  54. return -total;
  55. else
  56. return total; /* return result, negated if necessary */
  57. }