ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/compat.c
Revision: 8563
Committed: Sun Sep 23 11:39:44 2018 UTC (6 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 3488 byte(s)
Log Message:
- Update copyright years

File Contents

# User Rev Content
1 michael 5052 /*
2 michael 5351 * Copyright (c) 2002 Andy Smith
3 michael 8563 * Copyright (c) 2014-2018 ircd-hybrid development team
4 michael 5351 *
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 michael 5207 #include <string.h>
24 michael 5052
25     #include "compat.h"
26    
27 michael 8163 /* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */
28     /* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */
29 michael 5064 /*
30 michael 8163 * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
31 michael 5064 *
32 michael 8163 * Permission to use, copy, modify, and distribute this software for any
33     * purpose with or without fee is hereby granted, provided that the above
34     * copyright notice and this permission notice appear in all copies.
35 michael 5064 *
36 michael 8163 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37     * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38     * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39     * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40     * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41     * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42     * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43 michael 5064 */
44    
45     #ifndef HAVE_STRLCAT
46 michael 8163 /*
47     * Appends src to string dst of size dsize (unlike strncat, dsize is the
48     * full size of dst, not space left). At most dsize-1 characters
49     * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
50     * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
51     * If retval >= dsize, truncation occurred.
52     */
53 michael 5064 size_t
54 michael 8163 strlcat(char *dst, const char *src, size_t dsize)
55 michael 5064 {
56 michael 8163 const char *odst = dst;
57     const char *osrc = src;
58     size_t n = dsize;
59     size_t dlen;
60 michael 5064
61 michael 8163 /* Find the end of dst and adjust bytes left but don't go past end. */
62     while (n-- != 0 && *dst != '\0')
63     dst++;
64 michael 5064
65 michael 8163 dlen = dst - odst;
66     n = dsize - dlen;
67 michael 5064
68 michael 8163 if (n-- == 0)
69     return dlen + strlen(src);
70 michael 5064
71 michael 8163 while (*src != '\0')
72 michael 5064 {
73 michael 8163 if (n != 0)
74 michael 5064 {
75 michael 8163 *dst++ = *src;
76 michael 5064 n--;
77     }
78    
79 michael 8163 src++;
80 michael 5064 }
81    
82 michael 8163 *dst = '\0';
83    
84     return dlen + (src - osrc); /* count does not include NUL */
85 michael 5064 }
86     #endif
87    
88     #ifndef HAVE_STRLCPY
89 michael 8163 /*
90     * Copy string src to buffer dst of size dsize. At most dsize-1
91     * chars will be copied. Always NUL terminates (unless dsize == 0).
92     * Returns strlen(src); if retval >= dsize, truncation occurred.
93     */
94 michael 5064 size_t
95 michael 8163 strlcpy(char *dst, const char *src, size_t dsize)
96 michael 5064 {
97 michael 8163 const char *osrc = src;
98     size_t nleft = dsize;
99 michael 5064
100 michael 8163 /* Copy as many bytes as will fit. */
101     if (nleft != 0)
102 michael 5064 {
103 michael 8163 while (--nleft != 0)
104 michael 5064 {
105 michael 8163 if ((*dst++ = *src++) == '\0')
106 michael 5064 break;
107 michael 8163 }
108 michael 5064 }
109    
110 michael 8163 /* Not enough room in dst, add NUL and traverse rest of src. */
111     if (nleft == 0)
112 michael 5064 {
113 michael 8163 if (dsize != 0)
114     *dst = '\0'; /* NUL-terminate dst */
115    
116     while (*src++)
117 michael 5064 ;
118     }
119    
120 michael 8163 return src - osrc - 1; /* count does not include NUL */
121 michael 5064 }
122     #endif

Properties

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