strncpy
Peter da Silva
peter at ficc.uu.net
Wed Jan 24 14:08:23 AEST 1990
In article <9683 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
> > If it always
> > null-terminated, it couldn't be used for copies into a known fix-sized
> > buffer.
> Huh? strncpy(s1,s2,n) should work like the current strncpy(s1,s2,n)
> followed by s1[n - 1] = '\0' if necessary. That's a copy into a known
> fixed-size buffer, preserving null termination.
But what if you want to keep all !n! bytes of information? Then you have
to make your buffer 1 byte larger. Which can be a pain in a fixed
structure.
Let's put it this way. It's easy to implement *your* strncpy in the *real*
strncpy, but it's not even possible to do it the other way round.
> Since I do, in fact, always null-terminate the string myself, I'd prefer
> that strncpy do the job for me.
Since I don't, in fact, always null-terminate the string myself, I'm glad it
doesn't.
Meditate on struct utmp.
--
_--_|\ Peter da Silva. +1 713 274 5180. <peter at ficc.uu.net>.
/ \
\_.--._/ Xenix Support -- it's not just a job, it's an adventure!
v "Have you hugged your wolf today?" `-_-'
More information about the Comp.lang.c
mailing list