strxnmov.c
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 1k
Category:

MySQL

Development Platform:

Visual C++

  1. /*  File   : strxnmov.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 2 June 1984
  4.     Defines: strxnmov()
  5.     strxnmov(dst, len, src1, ..., srcn, NullS)
  6.     moves the first len characters of the concatenation of src1,...,srcn
  7.     to dst.  If there aren't that many characters, a NUL character will
  8.     be added to the end of dst to terminate it properly.  This gives the
  9.     same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a
  10.     large enough buffer, and then calling strnmov(dst, buff, len).
  11.     It is just like strnmov except that it concatenates multiple sources.
  12.     Beware: the last argument should be the null character pointer.
  13.     Take VERY great care not to omit it!  Also be careful to use NullS
  14.     and NOT to use 0, as on some machines 0 is not the same size as a
  15.     character pointer, or not the same bit pattern as NullS.
  16.     Note: strxnmov is like strnmov in that it moves up to len
  17.     characters; dst will be padded on the right with one NUL characters if
  18.     needed.
  19. */
  20. #include <global.h>
  21. #include "m_string.h"
  22. #include <stdarg.h>
  23. char *strxnmov(char *dst,uint len, const char *src, ...)
  24. {
  25.   va_list pvar;
  26.   char *end_of_dst=dst+len;
  27.   va_start(pvar,src);
  28.   while (src != NullS)
  29.   {
  30.     do
  31.     {
  32.       if (dst == end_of_dst)
  33. goto end;
  34.     }
  35.     while ((*dst++ = *src++));
  36.     dst--;
  37.     src = va_arg(pvar, char *);
  38.   }
  39.   *dst=0;
  40. end:
  41.   va_end(pvar);
  42.   return dst;
  43. }