ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/compat.c
Revision: 5351
Committed: Sun Jan 11 13:24:19 2015 UTC (10 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 3481 byte(s)
Log Message:
- Update license headers

File Contents

# User Rev Content
1 michael 5052 /*
2 michael 5351 * Copyright (c) 2002 Andy Smith
3     * Copyright (c) 2014-2015 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 michael 5052
21     #include "setup.h"
22    
23     #include <stdio.h>
24 michael 5207 #include <string.h>
25 michael 5052
26     #include "compat.h"
27    
28 michael 5064 /*
29     * strlcat and strlcpy were ripped from openssh 2.5.1p2
30     * They had the following Copyright info:
31     *
32     *
33     * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
34     * All rights reserved.
35     *
36     * Redistribution and use in source and binary forms, with or without
37     * modification, are permitted provided that the following conditions
38     * are met:
39     * 1. Redistributions of source code must retain the above copyright
40     * notice, this list of conditions and the following disclaimer.
41     * 2. Redistributions in binary form must reproduce the above copyright
42     * notice, this list of conditions and the following disclaimer in the
43     * documentation and/or other materials provided with the distribution.
44     * 3. The name of the author may not be used to endorse or promote products
45     * derived from this software without specific prior written permission.
46     *
47     * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
48     * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
49     * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
50     * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
51     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
52     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
53     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
54     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
55     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
56     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57     */
58    
59     #ifndef HAVE_STRLCAT
60     size_t
61     strlcat(char *dst, const char *src, size_t siz)
62     {
63     char *d = dst;
64     const char *s = src;
65     size_t n = siz, dlen;
66    
67     while (n-- != 0 && *d != '\0')
68     d++;
69    
70     dlen = d - dst;
71     n = siz - dlen;
72    
73     if (n == 0)
74     return dlen + strlen(s);
75    
76     while (*s != '\0')
77     {
78     if (n != 1)
79     {
80     *d++ = *s;
81     n--;
82     }
83    
84     s++;
85     }
86    
87     *d = '\0';
88     return dlen + (s - src); /* count does not include NUL */
89     }
90     #endif
91    
92     #ifndef HAVE_STRLCPY
93     size_t
94     strlcpy(char *dst, const char *src, size_t siz)
95     {
96     char *d = dst;
97     const char *s = src;
98     size_t n = siz;
99    
100     /* Copy as many bytes as will fit */
101     if (n != 0 && --n != 0)
102     {
103     do
104     {
105     if ((*d++ = *s++) == 0)
106     break;
107     } while (--n != 0);
108     }
109    
110     /* Not enough room in dst, add NUL and traverse rest of src */
111     if (n == 0)
112     {
113     if (siz != 0)
114     *d = '\0'; /* NUL-terminate dst */
115     while (*s++)
116     ;
117     }
118    
119     return s - src - 1; /* count does not include NUL */
120     }
121     #endif

Properties

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