~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/strmake.c

  • Committer: Monty Taylor
  • Date: 2008-08-01 23:59:59 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801235959-n8ypy9r5aohown77
Gettext error compiles and passes test!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  */
 
43
  uint n= 0;
 
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
}