This is fast strncpy implementation a-lГ Duff's device:
void * dps_strncpy(void *dst0, const void *src0, size_t length) {
if (length) {
register size_t n = (length + 7) / 8;
register char *dst = dst0, *src = src0;
switch(length % 8 ) {
case 0: do { if (!(*dst++ = *src++)) break;
case 7: if (!(*dst++ = *src++)) break;
case 6: if (!(*dst++ = *src++)) break;
case 5: if (!(*dst++ = *src++)) break;
case 4: if (!(*dst++ = *src++)) break;
case 3: if (!(*dst++ = *src++)) break;
case 2: if (!(*dst++ = *src++)) break;
case 1: if (!(*dst++ = *src++)) break;
} while(--n > 0);
}
}
return dst0;
}
N.B.: code is under GPL.