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.

167 lines
4.5 KiB

  1. /*----------------------------------------------------------------------------
  2. * File: RRCMCRT.C
  3. * Product: RTP/RTCP implementation.
  4. * Description: Provides Microsoft 'C' run-time support
  5. *
  6. * INTEL Corporation Proprietary Information
  7. * This listing is supplied under the terms of a license agreement with
  8. * Intel Corporation and may not be copied nor disclosed except in
  9. * accordance with the terms of that agreement.
  10. * Copyright (c) 1995 Intel Corporation.
  11. *--------------------------------------------------------------------------*/
  12. #include "rrcm.h"
  13. /*---------------------------------------------------------------------------
  14. / Global Variables
  15. /--------------------------------------------------------------------------*/
  16. /*---------------------------------------------------------------------------
  17. / External Variables
  18. /--------------------------------------------------------------------------*/
  19. #ifdef _DEBUG
  20. extern char debug_string[];
  21. #endif
  22. /*--------------------------------------------------------------------------
  23. * Function : RRCMsrand
  24. * Description: Seeds the random number generator with the int given.
  25. * Adapted from the BASIC random number generator.
  26. *
  27. * WARNING: There is no per thread seed. All threads of the process are
  28. * using the same seed.
  29. *
  30. * Input : seed: Seed
  31. *
  32. *
  33. * Return: None
  34. --------------------------------------------------------------------------*/
  35. static long holdrand = 1L;
  36. void RRCMsrand (unsigned int seed)
  37. {
  38. holdrand = (long)seed;
  39. }
  40. /*--------------------------------------------------------------------------
  41. * Function : RRCMrand
  42. * Description: Returns a pseudo-random number 0 through 32767.
  43. *
  44. * WARNING: There is no per thread number. All threads of the process
  45. * share the random number
  46. *
  47. * Input : None
  48. *
  49. * Return: Pseudo-random number 0 through 32767.
  50. --------------------------------------------------------------------------*/
  51. int RRCMrand (void)
  52. {
  53. return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
  54. }
  55. /***
  56. *char *_itoa, *_ltoa, *_ultoa(val, buf, radix) - convert binary int to ASCII
  57. * string
  58. *
  59. *Purpose:
  60. * Converts an int to a character string.
  61. *
  62. *Entry:
  63. * val - number to be converted (int, long or unsigned long)
  64. * int radix - base to convert into
  65. * char *buf - ptr to buffer to place result
  66. *
  67. *Exit:
  68. * fills in space pointed to by buf with string result
  69. * returns a pointer to this buffer
  70. *
  71. *Exceptions:
  72. *
  73. *******************************************************************************/
  74. /* helper routine that does the main job. */
  75. static void RRCMxtoa (unsigned long val,
  76. char *buf,
  77. unsigned radix,
  78. int is_neg)
  79. {
  80. char *p; /* pointer to traverse string */
  81. char *firstdig; /* pointer to first digit */
  82. char temp; /* temp char */
  83. unsigned digval; /* value of digit */
  84. p = buf;
  85. if (is_neg) {
  86. /* negative, so output '-' and negate */
  87. *p++ = '-';
  88. val = (unsigned long)(-(long)val);
  89. }
  90. firstdig = p; /* save pointer to first digit */
  91. do {
  92. digval = (unsigned) (val % radix);
  93. val /= radix; /* get next digit */
  94. /* convert to ascii and store */
  95. if (digval > 9)
  96. *p++ = (char) (digval - 10 + 'a'); /* a letter */
  97. else
  98. *p++ = (char) (digval + '0'); /* a digit */
  99. } while (val > 0);
  100. /* We now have the digit of the number in the buffer, but in reverse
  101. order. Thus we reverse them now. */
  102. *p-- = '\0'; /* terminate string; p points to last digit */
  103. do {
  104. temp = *p;
  105. *p = *firstdig;
  106. *firstdig = temp; /* swap *p and *firstdig */
  107. --p;
  108. ++firstdig; /* advance to next two digits */
  109. } while (firstdig < p); /* repeat until halfway */
  110. }
  111. /* Actual functions just call conversion helper with neg flag set correctly,
  112. and return pointer to buffer. */
  113. char *RRCMitoa (int val, char *buf, int radix)
  114. {
  115. if (radix == 10 && val < 0)
  116. RRCMxtoa((unsigned long)val, buf, radix, 1);
  117. else
  118. RRCMxtoa((unsigned long)(unsigned int)val, buf, radix, 0);
  119. return buf;
  120. }
  121. char *RRCMltoa (long val, char *buf, int radix)
  122. {
  123. RRCMxtoa((unsigned long)val, buf, radix, (radix == 10 && val < 0));
  124. return buf;
  125. }
  126. char *RRCMultoa (unsigned long val, char *buf, int radix)
  127. {
  128. RRCMxtoa(val, buf, radix, 0);
  129. return buf;
  130. }
  131. // [EOF]