safecpy.c 212 B

123456789101112
  1. #include <stdio.h>
  2. void
  3. safecpy(char *to, char *from, int tolen)
  4. {
  5. int fromlen;
  6. memset(to, 0, tolen);
  7. fromlen = from ? strlen(from) : 0;
  8. if (fromlen > tolen)
  9. fromlen = tolen;
  10. memcpy(to, from, fromlen);
  11. }