~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 <my_global.h>
28
#include "m_string.h"
29
30
char *strmake(register char *dst, register const char *src, size_t length)
31
{
32
#ifdef EXTRA_DEBUG
33
  /*
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.
43
  */
44
  uint n= 0;
45
  while (n < length && src[n++]);
46
  memset(dst + n, (int) 'Z', length - n + 1);
47
#endif
48
49
  while (length--)
50
    if (! (*dst++ = *src++))
51
      return dst-1;
52
  *dst=0;
53
  return dst;
54
}