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.

105 lines
2.6 KiB

  1. page ,132
  2. title strnset - set first n characters to one char.
  3. ;***
  4. ;strnset.asm - set first n characters to single character
  5. ;
  6. ; Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ; defines _strnset() - sets at most the first n characters of a string
  10. ; to a given character.
  11. ;
  12. ;Revision History:
  13. ; 11-18-83 RN initial version
  14. ; 05-18-88 SJM Add model-independent (large model) ifdef
  15. ; 05-23-88 WAJ If count = strlen(string)+1 then strlen+1 bytes were set.
  16. ; 08-04-88 SJM convert to cruntime/ add 32-bit support
  17. ; 08-23-88 JCR 386 cleanup
  18. ; 10-26-88 JCR General cleanup for 386-only code
  19. ; 03-23-90 GJF Changed to _stdcall. Also, fixed the copyright.
  20. ; 01-18-91 GJF ANSI naming.
  21. ; 05-10-91 GJF Back to _cdecl, sigh...
  22. ; 06-12-01 PML inc->add 1, dec->sub 1 for Pentium 4 perf (vs7#267015)
  23. ;
  24. ;*******************************************************************************
  25. .xlist
  26. include cruntime.inc
  27. .list
  28. page
  29. ;***
  30. ;char *_strnset(string, val, count) - set at most count characters to val
  31. ;
  32. ;Purpose:
  33. ; Sets the first count characters of string the character value.
  34. ; If the length of string is less than count, the length of
  35. ; string is used in place of n.
  36. ;
  37. ; Algorithm:
  38. ; char *
  39. ; _strnset (string, val, count)
  40. ; char *string,val;
  41. ; unsigned int count;
  42. ; {
  43. ; char *start = string;
  44. ;
  45. ; while (count-- && *string)
  46. ; *string++ = val;
  47. ; return(start);
  48. ; }
  49. ;
  50. ;Entry:
  51. ; char *string - string to set characters in
  52. ; char val - character to fill with
  53. ; unsigned count - count of characters to fill
  54. ;
  55. ;Exit:
  56. ; returns string, now filled with count copies of val.
  57. ;
  58. ;Uses:
  59. ;
  60. ;Exceptions:
  61. ;
  62. ;*******************************************************************************
  63. CODESEG
  64. public _strnset
  65. _strnset proc \
  66. uses edi ebx, \
  67. string:ptr byte, \
  68. val:byte, \
  69. count:IWORD
  70. mov edi,[string] ; di = string
  71. mov edx,edi ; dx=string addr; save return value
  72. mov ebx,[count] ; cx = max chars to set
  73. xor eax,eax ; null byte
  74. mov ecx,ebx
  75. jecxz short done ; zero length specified
  76. repne scasb ; find null byte & count bytes in cx
  77. jne short nonull ; null not found
  78. add ecx,1 ; don't want the null
  79. nonull:
  80. sub ebx,ecx ; bx=strlen (not null)
  81. mov ecx,ebx ; cx=strlen (not null)
  82. mov edi,edx ; restore string pointer
  83. mov al,val ; byte value
  84. rep stosb ; fill 'er up
  85. done:
  86. mov eax,edx ; return value: string addr
  87. ifdef _STDCALL_
  88. ret DPSIZE + 2*ISIZE ; _stdcall return
  89. else
  90. ret ; _cdecl return
  91. endif
  92. _strnset endp
  93. end