Hello,
I have create a wrapper for the strncpy function.
I will have to use this in my project which contains many headers and source files (about 20 all together). And this wrapper will be used in most of them.
As the code is very short I am wondering where is the best way to implement this wrapper into my project?
I am thinking this might be useful to have this in a header called utilities.h. And include this header in every source file that needs it?
And maybe any future projects as well?
I am new at C program, so just looking for some good guidance on this issue.
Many thanks,
/* Null terminate a string after coping */
char* strncpy_wrapper(char *dest, const char* source,
const size_t dest_size)
{
strncpy(dest, source, dest_size);
/*
* If the destination is greater than zero terminate with a null.
*/
if(dest_size > 0)
{
dest[dest_size - 1] = '\0';
}
return dest;
}