home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!utcsri!geac!lethe!druid!pseudo!mjn
- From: mjn@pseudo.uucp (Murray Nesbitt)
- Subject: Re: definition of strncpy stupid?
- Organization: Private system in Toronto, ON
- Date: Sat, 12 Dec 1992 10:12:57 GMT
- Message-ID: <MJN.92Dec12051258@pseudo.uucp>
- Lines: 28
- In-Reply-To: kaleb@jpl-devvax.jpl.nasa.gov's message of Thu, 10 Dec 1992 00:57:06 GMT
- References: <1992Dec8.181543.15339@dnbf01.bram.cdx.mot.com>
- <1992Dec8.210336.26009@rti.rti.org> <19924@ksr.com>
- <1992Dec10.005706.25200@jpl-devvax.jpl.nasa.gov>
- Sender: mjn@pseudo.uucp (Murray Nesbitt)
-
-
- kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley) writes:
-
- > And the beauty of C is that you can add anything you want; it'd be trivial
- > to add something like:
- >
- > #define strncpy0(s1,s2,n) strncpy (s1,s2,n);s1[n]='\0'
- >
- > to your application's headers. It's so trivial in fact that it makes me
- > wonder why this thread has gone on for so long...
-
- If you want to do it correctly, it's not quite so trivial.
-
- Given the behavior of the existing C library string functions, a
- programmer could reasonably expect to be able to do things like:
-
- strncpy0( strings[ i++ ], "Hello world\n", 5 );
-
- or,
-
- strcat( strncpy0( string, "Hello world\n", 5 ), " world\n" );
-
- but the former results in a serious bug, and the latter a syntax
- error.
-
- And, of course, the macro name is a member of the set of reserved
- names.
-
- --
- Murray
-