strncpy

Buster Irby rli at buster.irby.com
Fri Dec 22 09:07:57 AEST 1989


cns at stiatl.UUCP (Chris Straut) writes:

>I agree that strncpy should null terminate the resulting string.  The 
>definition of a string in the C language is a null terminated char array.
>And the function called (str)ncpy indicates a string operation, which by
>default should create a null terminated string.  To overcome this 'feature'
>we wrote our own strncpy function, which is benefical to the unsuspecting
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
>programmer (or novice), and the result is a null terminated string.

CAUTION: There is a lot of existing software in the world that
would break if the operation of strncpy or any other standard
library function were suddenly changed.  You are asking for
trouble any time you change the operation of a standard library
function such as strncpy, and I would strongly suggest that you
not do it.  First of all, what happens when you take a piece of
software that was not developed inhouse and compile it using your
new strncpy function?  Or what happens when you hire a senior
level C programmer who is used to the way strncpy is documented
to work?  You are asking for trouble, and believe me, it can cost
a lot of time and money to track down bugs which you introduce
into the code like this.  If you must create your own specialized
version of any standard library function, you should call it by
your own specialized name, not by its standard name.
-- 
Buster Irby  buster!rli



More information about the Comp.lang.c mailing list