forked from github/server
- strncpy replacement. ca. 50% schneller, weil kein überflüssiges
0-padding.
This commit is contained in:
parent
238cc9c778
commit
20e86659c3
1 changed files with 22 additions and 0 deletions
22
src/common/util/strncpy.c
Normal file
22
src/common/util/strncpy.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Faster replacement for ISO-C strncpy, does not pad with zeros
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
char *
|
||||||
|
strncpy(char *to, const char *from, size_t size)
|
||||||
|
{
|
||||||
|
char *t = to, *f = (char *)from;
|
||||||
|
int copied = 0;
|
||||||
|
|
||||||
|
while(copied < size) {
|
||||||
|
*t = *f;
|
||||||
|
if(*f == '\0') break;
|
||||||
|
t++; f++; copied++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue