~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
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.
6
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.
11
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 */
15
16
/*  File   : strmake.c
17
    Author : Michael Widenius
18
    Updated: 20 Jul 1984
19
    Defines: strmake()
20
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
25
*/
26
27
#include "m_string.h"
28
29
char *strmake(register char *dst, register const char *src, size_t length)
30
{
31
#ifdef EXTRA_DEBUG
32
  /*
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.
42
  */
482 by Brian Aker
Remove uint.
43
  uint32_t n= 0;
1 by brian
clean slate
44
  while (n < length && src[n++]);
45
  memset(dst + n, (int) 'Z', length - n + 1);
46
#endif
47
48
  while (length--)
49
    if (! (*dst++ = *src++))
50
      return dst-1;
51
  *dst=0;
52
  return dst;
53
}