~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/strxnmov.c

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002 MySQL AB
2
 
   
3
 
   This library is free software; you can redistribute it and/or
4
 
   modify it under the terms of the GNU Library General Public
5
 
   License as published by the Free Software Foundation; version 2
6
 
   of the License.
7
 
   
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
   
13
 
   You should have received a copy of the GNU Library General Public
14
 
   License along with this library; if not, write to the Free
15
 
   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16
 
   MA 02111-1307, USA */
17
 
 
18
 
/*  File   : strxnmov.c
19
 
    Author : Richard A. O'Keefe.
20
 
    Updated: 2 June 1984
21
 
    Defines: strxnmov()
22
 
 
23
 
    strxnmov(dst, len, src1, ..., srcn, NullS)
24
 
    moves the first len characters of the concatenation of src1,...,srcn
25
 
    to dst and add a closing NUL character.
26
 
    It is just like stpncpy except that it concatenates multiple sources.
27
 
    Beware: the last argument should be the null character pointer.
28
 
    Take VERY great care not to omit it!  Also be careful to use NullS
29
 
    and NOT to use 0, as on some machines 0 is not the same size as a
30
 
    character pointer, or not the same bit pattern as NullS.
31
 
 
32
 
    NOTE
33
 
      strxnmov is like stpncpy in that it moves up to len
34
 
      characters; dst will be padded on the right with one '\0' character.
35
 
      if total-string-length >= length then dst[length] will be set to \0
36
 
*/
37
 
 
38
 
#include "m_string.h"
39
 
#include <stdarg.h>
40
 
 
41
 
char *strxnmov(char *dst, size_t len, const char *src, ...)
42
 
{
43
 
  va_list pvar;
44
 
  char *end_of_dst=dst+len;
45
 
 
46
 
  va_start(pvar,src);
47
 
  while (src != (char *)0)
48
 
  {
49
 
    do
50
 
    {
51
 
      if (dst == end_of_dst)
52
 
        goto end;
53
 
    }
54
 
    while ((*dst++ = *src++));
55
 
    dst--;
56
 
    src = va_arg(pvar, char *);
57
 
  }
58
 
end:
59
 
  *dst=0;
60
 
  va_end(pvar);
61
 
  return dst;
62
 
}