strncat is insufficient

Shankar Unni shankar at hpclscu.HP.COM
Wed Aug 15 09:44:38 AEST 1990


Rahul: 
> Most of the time I want to avoid string overflow by
> doing this:
>    append str2 to str1, but cause at most n characters to be in str1.

Well, you could write a cheapo function that goes:

strlimcat (char *s1, char *s2, int n)
{
   strncat (s1, s2, (n - strlen(s1)));
}

which is exactly what strlimcat would have to do anyway..
 
Doug G:
> >I think the standard C library badly needs another function called,
> >say, strlimcat(), which limits the length of the destination string to
> >some value.
> 
> Feel free to implement one of these for your own applications.
> There isn't much point in discussing it in this newsgroup.
> We're not soliciting suggestions for changes to the standard.

Ooohhh. Does that mean that C is frozen for eternity? The "ultimate,
greatest-ever language on earth"?  I hardly think so.

I think this is an appropriate place for suggestions for extensions to the
language, too, in addition to questions about clarifications of items in
the current standard...

$0.02,
-----
Shankar Unni                                   E-Mail: 
Hewlett-Packard California Language Lab.     Internet: shankar at hpda.hp.com
Phone : (408) 447-5797                           UUCP: ...!hplabs!hpda!shankar



More information about the Comp.std.c mailing list