Source code of Windows XP (NT5)
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.

104 lines
2.4 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. ;
  23. ;*******************************************************************************
  24. .xlist
  25. include cruntime.inc
  26. .list
  27. page
  28. ;***
  29. ;char *_strnset(string, val, count) - set at most count characters to val
  30. ;
  31. ;Purpose:
  32. ; Sets the first count characters of string the character value.
  33. ; If the length of string is less than count, the length of
  34. ; string is used in place of n.
  35. ;
  36. ; Algorithm:
  37. ; char *
  38. ; _strnset (string, val, count)
  39. ; char *string,val;
  40. ; unsigned int count;
  41. ; {
  42. ; char *start = string;
  43. ;
  44. ; while (count-- && *string)
  45. ; *string++ = val;
  46. ; return(start);
  47. ; }
  48. ;
  49. ;Entry:
  50. ; char *string - string to set characters in
  51. ; char val - character to fill with
  52. ; unsigned count - count of characters to fill
  53. ;
  54. ;Exit:
  55. ; returns string, now filled with count copies of val.
  56. ;
  57. ;Uses:
  58. ;
  59. ;Exceptions:
  60. ;
  61. ;*******************************************************************************
  62. CODESEG
  63. public _strnset
  64. _strnset proc \
  65. uses edi ebx, \
  66. string:ptr byte, \
  67. val:byte, \
  68. count:IWORD
  69. mov edi,[string] ; di = string
  70. mov edx,edi ; dx=string addr; save return value
  71. mov ebx,[count] ; cx = max chars to set
  72. xor eax,eax ; null byte
  73. mov ecx,ebx
  74. jecxz short done ; zero length specified
  75. repne scasb ; find null byte & count bytes in cx
  76. jne short nonull ; null not found
  77. inc ecx ; don't want the null
  78. nonull:
  79. sub ebx,ecx ; bx=strlen (not null)
  80. mov ecx,ebx ; cx=strlen (not null)
  81. mov edi,edx ; restore string pointer
  82. mov al,val ; byte value
  83. rep stosb ; fill 'er up
  84. done:
  85. mov eax,edx ; return value: string addr
  86. ifdef _STDCALL_
  87. ret DPSIZE + 2*ISIZE ; _stdcall return
  88. else
  89. ret ; _cdecl return
  90. endif
  91. _strnset endp
  92. end