[Hijacked from freebsd-security]

On Thu, 15 Jul 1999 17:33:29 -0400, Garance A Drosihn wrote:

> What I wanted to do was have "estr" routines, where the destination
> is specified as the starting point and the ending point of the area
> available for the string (as two parameters).  The routines would
> return the position of the current string-terminator.  So you could
> do things like:

As I understand it, the goal here is to return to the caller the number
of bytes copied (however you represent it), so that the caller can
easily determine whether or not dst is safe for operations demanding a
null-terminated string.

If that is true, then I think the interface you propose is overly
complex. Looking at the existing functions, their only flaw is that they
return known (and therefore useless) information, "wasting" the return
value. All we need is:

size_t
foocpy(char *dst, const char *src)

size_t
fooncpy(char *dst, const char *src, size_t len)

size_t
foocat(char *s, const char *append)

size_t
fooncat(char *s, const char *append, size_t count)

where the return value is the number of bytes {copied,appended}.

Since the goal is simply to make it easier to do what is already
possible, I think that this approach is better than what you're
suggesting, since the pointer arithmetic required in the caller is
simpler.

And since the prototypes for fooncpy and fooncat above match exactly
those of the proposed strlcpy and strlcat respectively (just had a
look before I "hit the send button"), I'd say that the latter two are
definitely the functions you want.

Ciao,
Sheldon.


To Unsubscribe: send mail to majord...@freebsd.org
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to