logo

utils-std

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

t_strlcpy.c (1083B)


  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 "../libutils/lib_string.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #define MATCH(a, b) \
  9. if(a != b) \
  10. { \
  11. printf(#a "(%d) != " #b "(%d)\n", a, b); \
  12. abort(); \
  13. }
  14. int
  15. main(void)
  16. {
  17. const char *test = "this is a test string";
  18. static char buf[64];
  19. buf[10] = 'A';
  20. puts("1..1");
  21. size_t ret = lib_strlcpy(buf, test, 10);
  22. MATCH((int)ret, 9);
  23. MATCH(buf[10], 'A');
  24. MATCH(buf[9], '\0');
  25. MATCH(strncmp(buf, test, 9), 0);
  26. puts("1 ok - strlcpy");
  27. return 0;
  28. }