memset.c 500 B

1234567891011121314151617181920212223242526
  1. /* memset
  2. This implementation is in the public domain. */
  3. /*
  4. @deftypefn Supplemental void* memset (void *@var{s}, int @var{c}, @
  5. size_t @var{count})
  6. Sets the first @var{count} bytes of @var{s} to the constant byte
  7. @var{c}, returning a pointer to @var{s}.
  8. @end deftypefn
  9. */
  10. #include <ansidecl.h>
  11. #include <stddef.h>
  12. PTR
  13. memset (PTR dest, register int val, register size_t len)
  14. {
  15. register unsigned char *ptr = (unsigned char*)dest;
  16. while (len-- > 0)
  17. *ptr++ = val;
  18. return dest;
  19. }