strxfrm.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* vi: set sw=4 ts=4: */
  2. /* strxfrm for uClibc
  3. *
  4. * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Library General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <string.h>
  21. size_t strxfrm(char *dst, const char *src, size_t len)
  22. {
  23. size_t length;
  24. register char *ptr1, *ptr2;
  25. length = len;
  26. ptr1 = (char *) dst;
  27. ptr2 = (char *) src;
  28. while (length--) {
  29. if (*ptr2)
  30. *ptr1++ = *ptr2++;
  31. else
  32. *ptr1++ = '\0';
  33. }
  34. /* The first while loop should have done much of the heavy
  35. * lifting for us. This second look will finish the job if
  36. * that is necessary */
  37. while (*ptr2)
  38. ptr2++;
  39. length = (ptr2 - src);
  40. if (length<len)
  41. return(length);
  42. return(len);
  43. }