logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

lib_strlcpy.c (408B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #include "./lib_string.h"
  5. size_t
  6. lib_strlcpy(char *restrict d, const char *restrict s, size_t dz)
  7. {
  8. if(!dz--) return 0;
  9. char *d0 = d;
  10. while(dz > 0 && (*d = *s) != '\0')
  11. dz--, s++, d++;
  12. *d = '\0';
  13. return d - d0;
  14. }