libc_string.c 850 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  3. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  4. */
  5. #include "ua_config.h"
  6. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n) {
  7. unsigned char *d = dest;
  8. const unsigned char *s = src;
  9. while(n--)
  10. *d++ = *s++;
  11. return dest;
  12. }
  13. void *memset(void *dest, int c, size_t n) {
  14. unsigned char c8 = (unsigned char)c;
  15. unsigned char *target = dest;
  16. while(n--)
  17. *target++ = c8;
  18. return dest;
  19. }
  20. size_t strlen(const char *str) {
  21. size_t len = 0;
  22. for(const char *s = str; *s; s++, len++);
  23. return len;
  24. }
  25. int memcmp(const void *vl, const void *vr, size_t n) {
  26. const unsigned char *l = vl, *r = vr;
  27. for(; n && *l == *r; n--, l++, r++);
  28. return n ? *l-*r : 0;
  29. }