1/* Copyright Richard A. O'Keefe.
2 Copyright (c) 2000 TXT DataKonsult Ab & Monty Program Ab
3 Copyright (c) 2009-2011, Monty Program Ab
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must the following disclaimer in
13 the documentation and/or other materials provided with the
14 distribution.
15
16 THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY
17 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28*/
29
30/* File : strxnmov.c
31 Author : Richard A. O'Keefe.
32 Updated: 2 June 1984
33 Defines: strxnmov()
34
35 strxnmov(dst, len, src1, ..., srcn, NullS)
36 moves the first len characters of the concatenation of src1,...,srcn
37 to dst and add a closing NUL character.
38 It is just like strnmov except that it concatenates multiple sources.
39 Beware: the last argument should be the null character pointer.
40 Take VERY great care not to omit it! Also be careful to use NullS
41 and NOT to use 0, as on some machines 0 is not the same size as a
42 character pointer, or not the same bit pattern as NullS.
43
44 NOTE
45 strxnmov is like strnmov in that it moves up to len
46 characters; dst will be padded on the right with one '\0' character.
47 if total-string-length >= length then dst[length] will be set to \0
48*/
49
50#include "strings_def.h"
51#include <stdarg.h>
52
53char *strxnmov(char *dst, size_t len, const char *src, ...)
54{
55 va_list pvar;
56 char *end_of_dst=dst+len;
57
58 va_start(pvar,src);
59 while (src != NullS)
60 {
61 do
62 {
63 if (dst == end_of_dst)
64 goto end;
65 }
66 while ((*dst++ = *src++));
67 dst--;
68 src = va_arg(pvar, char *);
69 }
70end:
71 *dst=0;
72 va_end(pvar);
73 return dst;
74}
75