ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/compat.c
Revision: 7005
Committed: Fri Jan 1 00:06:56 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 3462 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * Copyright (c) 2002 Andy Smith
3 * Copyright (c) 2014-2016 ircd-hybrid development team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20
21 #include "setup.h"
22
23 #include <string.h>
24
25 #include "compat.h"
26
27 /*
28 * strlcat and strlcpy were ripped from openssh 2.5.1p2
29 * They had the following Copyright info:
30 *
31 *
32 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
33 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. The name of the author may not be used to endorse or promote products
44 * derived from this software without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
47 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
48 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
49 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
50 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
52 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
53 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
54 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57
58 #ifndef HAVE_STRLCAT
59 size_t
60 strlcat(char *dst, const char *src, size_t siz)
61 {
62 char *d = dst;
63 const char *s = src;
64 size_t n = siz, dlen;
65
66 while (n-- != 0 && *d != '\0')
67 d++;
68
69 dlen = d - dst;
70 n = siz - dlen;
71
72 if (n == 0)
73 return dlen + strlen(s);
74
75 while (*s != '\0')
76 {
77 if (n != 1)
78 {
79 *d++ = *s;
80 n--;
81 }
82
83 s++;
84 }
85
86 *d = '\0';
87 return dlen + (s - src); /* count does not include NUL */
88 }
89 #endif
90
91 #ifndef HAVE_STRLCPY
92 size_t
93 strlcpy(char *dst, const char *src, size_t siz)
94 {
95 char *d = dst;
96 const char *s = src;
97 size_t n = siz;
98
99 /* Copy as many bytes as will fit */
100 if (n != 0 && --n != 0)
101 {
102 do
103 {
104 if ((*d++ = *s++) == 0)
105 break;
106 } while (--n != 0);
107 }
108
109 /* Not enough room in dst, add NUL and traverse rest of src */
110 if (n == 0)
111 {
112 if (siz != 0)
113 *d = '\0'; /* NUL-terminate dst */
114 while (*s++)
115 ;
116 }
117
118 return s - src - 1; /* count does not include NUL */
119 }
120 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Id