Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    dest[0] = '\0';
    strncat(dest, src, size);


Sure. Or:

  strncpy(dest, src, size);
  dest[size - 1] = '\0';


The fact that strncpy zeros the buffer may make it slower.


Sure, by a couple of cycles. Unless your size is huge. In which case, perhaps you should try to avoid copying strings in the first place.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: