1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Author : Michael Widenius
21
strmake(dst,src,length) moves length characters, or until end, of src to
22
dst and appends a closing NUL to dst.
23
Note that if strlen(src) >= length then dst[length] will be set to \0
24
strmake() returns pointer to closing null
27
#include <my_global.h>
30
char *strmake(register char *dst, register const char *src, size_t length)
34
'length' is the maximum length of the string; the buffer needs
35
to be one character larger to accomodate the terminating '\0'.
36
This is easy to get wrong, so we make sure we write to the
37
entire length of the buffer to identify incorrect buffer-sizes.
38
We only initialise the "unused" part of the buffer here, a) for
39
efficiency, and b) because dst==src is allowed, so initialising
40
the entire buffer would overwrite the source-string. Also, we
41
write a character rather than '\0' as this makes spotting these
42
problems in the results easier.
45
while (n < length && src[n++]);
46
memset(dst + n, (int) 'Z', length - n + 1);
50
if (! (*dst++ = *src++))