Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!lavaca.uh.edu!uhnix1!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: strncpy Message-ID: Date: 24 Jan 90 03:08:23 GMT References: <11527@csli.Stanford.EDU> <000003Q@cdis-1.UUCP> <11616@csli.Stanford.EDU> <48314938.f69e@phobos.UUCP> <11864@csli.Stanford.EDU> <9683@stealth.acf.nyu.edu> Reply-To: peter@ficc.uu.net (Peter da Silva) Distribution: usa Organization: Xenix Support, FICC Lines: 23 In article <9683@stealth.acf.nyu.edu> brnstnd@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. . / \ \_.--._/ Xenix Support -- it's not just a job, it's an adventure! v "Have you hugged your wolf today?" `-_-'