home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18250 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.4 KB  |  45 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!utcsri!geac!lethe!druid!pseudo!mjn
  3. From: mjn@pseudo.uucp (Murray Nesbitt)
  4. Subject: Re: definition of strncpy stupid?
  5. Organization: Private system in Toronto, ON
  6. Date: Sat, 12 Dec 1992 10:12:57 GMT
  7. Message-ID: <MJN.92Dec12051258@pseudo.uucp>
  8. Lines: 28
  9. In-Reply-To: kaleb@jpl-devvax.jpl.nasa.gov's message of Thu, 10 Dec 1992 00:57:06 GMT
  10. References: <1992Dec8.181543.15339@dnbf01.bram.cdx.mot.com>
  11.     <1992Dec8.210336.26009@rti.rti.org> <19924@ksr.com>
  12.     <1992Dec10.005706.25200@jpl-devvax.jpl.nasa.gov>
  13. Sender: mjn@pseudo.uucp (Murray Nesbitt)
  14.  
  15.  
  16. kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley) writes:
  17.  
  18. > And the beauty of C is that you can add anything you want; it'd be trivial
  19. > to add something like:
  20. >
  21. >     #define strncpy0(s1,s2,n) strncpy (s1,s2,n);s1[n]='\0'
  22. >
  23. > to your application's headers.  It's so trivial in fact that it makes me 
  24. > wonder why this thread has gone on for so long...
  25.  
  26. If you want to do it correctly, it's not quite so trivial.
  27.  
  28. Given the behavior of the existing C library string functions, a
  29. programmer could reasonably expect to be able to do things like:
  30.  
  31.     strncpy0( strings[ i++ ], "Hello world\n", 5 );
  32.  
  33. or,
  34.  
  35.     strcat( strncpy0( string, "Hello world\n", 5 ), " world\n" );
  36.  
  37. but the former results in a serious bug, and the latter a syntax
  38. error.
  39.  
  40. And, of course, the macro name is a member of the set of reserved
  41. names.
  42.  
  43. -- 
  44. Murray
  45.