strdup.c 705 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #include <stdlib.h>
  9. #ifdef WANT_WIDE
  10. libc_hidden_proto(wcslen)
  11. # define Wstrdup wcsdup
  12. # define Wstrlen wcslen
  13. #else
  14. libc_hidden_proto(strdup)
  15. libc_hidden_proto(strlen)
  16. # define Wstrdup strdup
  17. # define Wstrlen strlen
  18. #endif
  19. libc_hidden_proto(memcpy)
  20. Wchar *Wstrdup(register const Wchar *s1)
  21. {
  22. register Wchar *s;
  23. register size_t l = (Wstrlen(s1) + 1) * sizeof(Wchar);
  24. if ((s = malloc(l)) != NULL) {
  25. memcpy(s, s1, l);
  26. }
  27. return s;
  28. }
  29. #ifndef WANT_WIDE
  30. libc_hidden_weak(strdup)
  31. #endif