home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18216 < prev    next >
Encoding:
Internet Message Format  |  1992-12-11  |  1.7 KB

  1. 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
  2. From: bkottmann@falcon.aamrl.wpafb.af.mil (Brett Kottmann)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: No, but strncat() is stupid (was: definition of strncpy stupid?)
  5. Message-ID: <1992Dec11.095325.1871@falcon.aamrl.wpafb.af.mil>
  6. Date: 11 Dec 92 09:53:25 EST
  7. References: <DAVIS.92Dec8113707@pacific.mps.ohio-state.edu>  <1992Dec10.175103.11502@newshost.lanl.gov>
  8. Organization: Logicon Technical Services, Inc.
  9. Lines: 27
  10.  
  11. In article <1992Dec10.175103.11502@newshost.lanl.gov>, jlg@cochiti.lanl.gov (J. Giles) writes:
  12. > It's not strncpy() that's poorly designed, but strncat().
  13. > Suppose I have a string for which I've reserved N bytes of
  14. > space.  I want to have string handling functions which 
  15. > provide an easy way to make sure I never run past that
  16. > length when manipulating the string.  The strncpy() function
  17. > does this as well as possible under a function call
  18. > paradigm.  However, consider the strncat() function:
  19. > I can't simply say 
  20. >    strncat(s1,s2,N);
  21. > This would *add* N characters to s1, not limit it's total length
  22. > to N.  In order to do what I want, I have to:
  23. >    strncat(s1, s2, N - strlen(s1));
  24. > Except, I can't do this either.  Previous operations on s1 may 
  25. > have left it without null termination - so strlen() won't work.
  26.  
  27.     It better have null termination.  strncat uses that to start storing
  28. s2.
  29.  
  30. Brett
  31. "The opinions and views expressed here are strictly my own and do not 
  32. necessarily reflect the official position of either the U.S. Air Force 
  33. or its contractors."
  34.