strlcat.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ** Copyright 2002, Manuel J. Petit. All rights reserved.
  3. ** Distributed under the terms of the NewOS License.
  4. */
  5. /*
  6. * Copyright (c) 2008 Travis Geiselbrecht
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files
  10. * (the "Software"), to deal in the Software without restriction,
  11. * including without limitation the rights to use, copy, modify, merge,
  12. * publish, distribute, sublicense, and/or sell copies of the Software,
  13. * and to permit persons to whom the Software is furnished to do so,
  14. * subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  22. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #include <string.h>
  28. #include <sys/types.h>
  29. size_t
  30. strlcat(char *dst, char const *src, size_t s)
  31. {
  32. size_t i;
  33. size_t j= strnlen(dst, s);
  34. if(!s) {
  35. return j+strlen(src);
  36. }
  37. dst+= j;
  38. for(i= 0; ((i< s-1) && src[i]); i++) {
  39. dst[i]= src[i];
  40. }
  41. dst[i]= 0;
  42. return j + i + strlen(src+i);
  43. }