libc_string.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  6. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  7. */
  8. #include "ua_config.h"
  9. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n) {
  10. unsigned char *d = dest;
  11. const unsigned char *s = src;
  12. while(n--)
  13. *d++ = *s++;
  14. return dest;
  15. }
  16. void *memset(void *dest, int c, size_t n) {
  17. unsigned char c8 = (unsigned char)c;
  18. unsigned char *target = dest;
  19. while(n--)
  20. *target++ = c8;
  21. return dest;
  22. }
  23. size_t strlen(const char *str) {
  24. size_t len = 0;
  25. for(const char *s = str; *s; s++, len++);
  26. return len;
  27. }
  28. int memcmp(const void *vl, const void *vr, size_t n) {
  29. const unsigned char *l = vl, *r = vr;
  30. for(; n && *l == *r; n--, l++, r++);
  31. return n ? *l-*r : 0;
  32. }