This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: PATCH: safe string copy and concetation
- To: James Antill <james at and dot org>
- Subject: Re: PATCH: safe string copy and concetation
- From: Kaz Kylheku <kaz at ashi dot footprints dot net>
- Date: Tue, 8 Aug 2000 18:59:45 -0700 (PDT)
- cc: Chiaki Ishikawa <Chiaki dot Ishikawa at personal-media dot co dot jp>, libc-alpha at sources dot redhat dot com
On 8 Aug 2000, James Antill wrote:
> Anyway the functions given could be trivially implemented (1 to 2
> lines each via. calls to sprintf()) if you really need them.
Certainly, strlcpy is easy:
#define strlcpy(a, b, c) sprintf(a, "%.*s", b, (int) ((c)-1))
Did I get that right? The idea is to copy at most c-1 characters from string a
to buffer b (which must not overlap a) and null terminate.
The snprintf() function which is already in glibc and available under
_GNU_SOURCE can be used to easily do the equivalent of strlcat.