strdup.c 601 B

123456789101112131415161718192021222324252627282930313233
  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. # define Wstrdup wcsdup
  11. # define Wstrlen wcslen
  12. #else
  13. # define Wstrdup strdup
  14. # define Wstrlen strlen
  15. #endif
  16. Wchar *Wstrdup(register const Wchar *s1)
  17. {
  18. register Wchar *s;
  19. register size_t l = (Wstrlen(s1) + 1) * sizeof(Wchar);
  20. if ((s = malloc(l)) != NULL) {
  21. memcpy(s, s1, l);
  22. }
  23. return s;
  24. }
  25. #ifndef WANT_WIDE
  26. libc_hidden_weak(strdup)
  27. #endif