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
29
char *strmake(register char *dst, register const char *src, size_t length)
33
'length' is the maximum length of the string; the buffer needs
34
to be one character larger to accomodate the terminating '\0'.
35
This is easy to get wrong, so we make sure we write to the
36
entire length of the buffer to identify incorrect buffer-sizes.
37
We only initialise the "unused" part of the buffer here, a) for
38
efficiency, and b) because dst==src is allowed, so initialising
39
the entire buffer would overwrite the source-string. Also, we
40
write a character rather than '\0' as this makes spotting these
41
problems in the results easier.
44
while (n < length && src[n++]);
45
memset(dst + n, (int) 'Z', length - n + 1);
49
if (! (*dst++ = *src++))