strncpy

Maarten Litmaath maart at cs.vu.nl
Fri Dec 22 06:24:24 AEST 1989


In article <11509 at csli.Stanford.EDU> poser at csli.Stanford.EDU (Bill Poser) writes:
\
\	Why is it that strncpy(3) does not null terminate
\the string if the length of the source string is greater than
\or equal to the length of the target buffer? I cannot think of
\any circumstances in which this behaviour is desirable, and
\always end up null terminating it myself. [...]

So you have to write nstrncpy(), a function that always null-terminates the
destination, just like you have to write your own str*c{at,py} functions if
you want them to return something USEFUL, instead of their first arguments,
e.g. the new length of the destination. :-(
-- 
1755 EST, Dec 14, 1992: Henry Spencer is put on a one-way mission to the moon.|
  Maarten Litmaath @ VU Amsterdam:  maart at cs.vu.nl,  uunet!mcsun!botter!maart



More information about the Comp.lang.c mailing list