strdup.c 755 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. libc_hidden_proto(wcscpy)
  12. # define Wstrdup wcsdup
  13. # define Wstrlen wcslen
  14. # define Wstrcpy wcscpy
  15. #else
  16. libc_hidden_proto(strdup)
  17. libc_hidden_proto(strlen)
  18. libc_hidden_proto(strcpy)
  19. # define Wstrdup strdup
  20. # define Wstrlen strlen
  21. # define Wstrcpy strcpy
  22. #endif
  23. Wchar *Wstrdup(register const Wchar *s1)
  24. {
  25. register Wchar *s;
  26. if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
  27. Wstrcpy(s, s1);
  28. }
  29. return s;
  30. }
  31. #ifndef WANT_WIDE
  32. libc_hidden_def(strdup)
  33. #endif