OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [string/] [wcslcat.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
FUNCTION
3
        <<wcslcat>>---concatenate wide-character strings to specified length
4
 
5
ANSI_SYNOPSIS
6
        #include <wchar.h>
7
        size_t wcslcat(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
8
 
9
TRAD_SYNOPSIS
10
        #include <wchar.h>
11
        size_t wcslcat(<[dst]>, <[src]>, <[siz]>
12
        wchar_t *<[dst]>;
13
        const wchar_t *<[src]>;
14
        size_t <[siz]>;
15
 
16
DESCRIPTION
17
        The <<wcslcat>> function appends wide characters from <[src]> to
18
        end of the <[dst]> wide-character string so that the resultant
19
        wide-character string is not more than <[siz]> wide characters
20
        including the terminating null wide-character code.  A terminating
21
        null wide character is always added unless <[siz]> is 0.  Thus,
22
        the maximum number of wide characters that can be appended from
23
        <[src]> is <[siz]> - 1. If copying takes place between objects
24
        that overlap, the behaviour is undefined.
25
 
26
RETURNS
27
        Wide-character string length of initial <[dst]> plus the
28
        wide-character string length of <[src]> (does not include
29
        terminating null wide-characters).  If the return value is
30
        greater than or equal to <[siz]>, then truncation occurred and
31
        not all wide characters from <[src]> were appended.
32
 
33
PORTABILITY
34
No supporting OS subroutines are required.
35
*/
36
 
37
/*      $NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $       */
38
/*      from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp    */
39
 
40
/*
41
 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
42
 * All rights reserved.
43
 *
44
 * Redistribution and use in source and binary forms, with or without
45
 * modification, are permitted provided that the following conditions
46
 * are met:
47
 * 1. Redistributions of source code must retain the above copyright
48
 *    notice, this list of conditions and the following disclaimer.
49
 * 2. Redistributions in binary form must reproduce the above copyright
50
 *    notice, this list of conditions and the following disclaimer in the
51
 *    documentation and/or other materials provided with the distribution.
52
 * 3. The name of the author may not be used to endorse or promote products
53
 *    derived from this software without specific prior written permission.
54
 *
55
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
56
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
57
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
58
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
59
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
61
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
62
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
63
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
64
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65
 */
66
 
67
#include <_ansi.h>
68
#include <wchar.h>
69
 
70
/*
71
 * Appends src to string dst of size siz (unlike wcsncat, siz is the
72
 * full size of dst, not space left).  At most siz-1 characters
73
 * will be copied.  Always NUL terminates (unless siz == 0).
74
 * Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
75
 * truncation occurred.
76
 */
77
size_t
78
_DEFUN (wcslcat, (dst, src, siz),
79
        wchar_t * dst _AND
80
        _CONST wchar_t * src _AND
81
        size_t siz)
82
{
83
  wchar_t *d = dst;
84
  _CONST wchar_t *s = src;
85
  size_t n = siz;
86
  size_t dlen;
87
 
88
  /* Find the end of dst and adjust bytes left but don't go past end */
89
  while (*d != '\0' && n-- != 0)
90
    d++;
91
  dlen = d - dst;
92
  n = siz - dlen;
93
 
94
  if (n == 0)
95
    return (dlen + wcslen (s));
96
  while (*s != '\0')
97
    {
98
      if (n != 1)
99
        {
100
          *d++ = *s;
101
          n--;
102
        }
103
      s++;
104
    }
105
  *d = '\0';
106
 
107
  return (dlen + (s - src));    /* count does not include NUL */
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.