home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!europa.asd.contel.com!emory!swrinde!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!falcon.aamrl.wpafb.af.mil!bkottmann
- From: bkottmann@falcon.aamrl.wpafb.af.mil (Brett Kottmann)
- Newsgroups: comp.lang.c
- Subject: Re: No, but strncat() is stupid (was: definition of strncpy stupid?)
- Message-ID: <1992Dec11.095325.1871@falcon.aamrl.wpafb.af.mil>
- Date: 11 Dec 92 09:53:25 EST
- References: <DAVIS.92Dec8113707@pacific.mps.ohio-state.edu> <1992Dec10.175103.11502@newshost.lanl.gov>
- Organization: Logicon Technical Services, Inc.
- Lines: 27
-
- In article <1992Dec10.175103.11502@newshost.lanl.gov>, jlg@cochiti.lanl.gov (J. Giles) writes:
- > It's not strncpy() that's poorly designed, but strncat().
- > Suppose I have a string for which I've reserved N bytes of
- > space. I want to have string handling functions which
- > provide an easy way to make sure I never run past that
- > length when manipulating the string. The strncpy() function
- > does this as well as possible under a function call
- > paradigm. However, consider the strncat() function:
- > I can't simply say
- >
- > strncat(s1,s2,N);
- >
- > This would *add* N characters to s1, not limit it's total length
- > to N. In order to do what I want, I have to:
- >
- > strncat(s1, s2, N - strlen(s1));
- >
- > Except, I can't do this either. Previous operations on s1 may
- > have left it without null termination - so strlen() won't work.
-
- It better have null termination. strncat uses that to start storing
- s2.
-
- Brett
- "The opinions and views expressed here are strictly my own and do not
- necessarily reflect the official position of either the U.S. Air Force
- or its contractors."
-