You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.0 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (c) 2000, 2001, 2003, 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc.
  2. Use is subject to license terms.
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  13. */
  14. /* File : strmake.c
  15. Author : Michael Widenius
  16. Updated: 20 Jul 1984
  17. Defines: strmake()
  18. strmake(dst,src,length) moves length characters, or until end, of src to
  19. dst and appends a closing NUL to dst.
  20. Note that if strlen(src) >= length then dst[length] will be set to \0
  21. strmake() returns pointer to closing null
  22. */
  23. #include <my_global.h>
  24. #include "m_string.h"
  25. char *strmake(register char *dst, register const char *src, size_t length)
  26. {
  27. #ifdef EXTRA_DEBUG
  28. /*
  29. 'length' is the maximum length of the string; the buffer needs
  30. to be one character larger to accomodate the terminating '\0'.
  31. This is easy to get wrong, so we make sure we write to the
  32. entire length of the buffer to identify incorrect buffer-sizes.
  33. We only initialise the "unused" part of the buffer here, a) for
  34. efficiency, and b) because dst==src is allowed, so initialising
  35. the entire buffer would overwrite the source-string. Also, we
  36. write a character rather than '\0' as this makes spotting these
  37. problems in the results easier.
  38. */
  39. uint n= 0;
  40. while (n < length && src[n++]);
  41. memset(dst + n, (int) 'Z', length - n + 1);
  42. #endif
  43. while (length--)
  44. if (! (*dst++ = *src++))
  45. return dst-1;
  46. *dst=0;
  47. return dst;
  48. }