strncpy() (was: gets(3) nonsense)

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Nov 18 12:39:10 AEST 1988


In article <1666 at solo10.cs.vu.nl> maart at cs.vu.nl (Litmaath Maarten) writes:
>If you want to copy part of a string into a buffer, do you complain you can't
>give a count to strcpy()? Or do you say: hey, strcpy() doesn't do what I want,
>let's use another function (which happens to be strncpy())?

Except strncpy() has its own problems when the limit is reached,
just as someone observed that fgets() does!

The important idea is that one must think HARD about the implications
of the specifications for library functions, in order to use them
safely in robust, secure code.  There is no easy road to rightness.



More information about the Comp.lang.c mailing list