💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › dcd695a97df859b54ca98380fa15e… captured on 2023-09-08 at 16:24:20. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-19)
-=-=-=-=-=-=-
0 #include "str.h"
1 #ifdef NO_STRLCPY
2 /*
3 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/types.h>
19 #include <string.h>
20
21 /*
22 * Copy string src to buffer dst of size dsize. At most dsize-1
23 * chars will be copied. Always NUL terminates (unless dsize == 0).
24 * Returns strlen(src); if retval >= dsize, truncation occurred.
25 */
26 size_t
27 strlcpy(char *dst, const char *src, size_t dsize)
28 {
29 const char *osrc = src;
30 size_t nleft = dsize;
31
32 /* Copy as many bytes as will fit. */
33 if (nleft != 0) {
34 while (--nleft != 0) {
35 if ((*dst++ = *src++) == '\0')
36 break;
37 }
38 }
39
40 /* Not enough room in dst, add NUL and traverse rest of src. */
41 if (nleft == 0) {
42 if (dsize != 0)
43 *dst = '\0'; /* NUL-terminate dst */
44 while (*src++)
45 ;
46 }
47
48 return(src - osrc - 1); /* count does not include NUL */
49 }
50 #endif
51
52 #ifdef NO_STRLCAT
53 /*
54 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
55 *
56 * Permission to use, copy, modify, and distribute this software for any
57 * purpose with or without fee is hereby granted, provided that the above
58 * copyright notice and this permission notice appear in all copies.
59 *
60 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
61 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
62 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
63 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
64 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
65 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
66 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
67 */
68
69 #include <sys/types.h>
70 #include <string.h>
71
72 /*
73 * Appends src to string dst of size dsize (unlike strncat, dsize is the
74 * full size of dst, not space left). At most dsize-1 characters
75 * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
76 * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
77 * If retval >= dsize, truncation occurred.
78 */
79 size_t
80 strlcat(char *dst, const char *src, size_t dsize)
81 {
82 const char *odst = dst;
83 const char *osrc = src;
84 size_t n = dsize;
85 size_t dlen;
86
87 /* Find the end of dst and adjust bytes left but don't go past end. */
88 while (n-- != 0 && *dst != '\0')
89 dst++;
90 dlen = dst - odst;
91 n = dsize - dlen;
92
93 if (n-- == 0)
94 return(dlen + strlen(src));
95 while (*src != '\0') {
96 if (n != 0) {
97 *dst++ = *src;
98 n--;
99 }
100 src++;
101 }
102 *dst = '\0';
103
104 return(dlen + (src - osrc)); /* count does not include NUL */
105 }
106 #endif
107
108 #ifdef NO_STRNSTR
109 /*-
110 * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
111 * Copyright (c) 1990, 1993
112 * The Regents of the University of California. All rights reserved.
113 *
114 * This code is derived from software contributed to Berkeley by
115 * Chris Torek.
116 *
117 * Redistribution and use in source and binary forms, with or without
118 * modification, are permitted provided that the following conditions
119 * are met:
120 * 1. Redistributions of source code must retain the above copyright
121 * notice, this list of conditions and the following disclaimer.
122 * 2. Redistributions in binary form must reproduce the above copyright
123 * notice, this list of conditions and the following disclaimer in the
124 * documentation and/or other materials provided with the distribution.
125 * 3. Neither the name of the University nor the names of its contributors
126 * may be used to endorse or promote products derived from this software
127 * without specific prior written permission.
128 *
129 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
130 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
131 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
132 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
133 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
134 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
135 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
136 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
137 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
138 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
139 * SUCH DAMAGE.
140 */
141
142 #if __has_include(<sys/cdefs.h>)
143 #include <sys/cdefs.h>
144 #endif
145 #include <string.h>
146
147 /*
148 * Find the first occurrence of find in s, where the search is limited to the
149 * first slen characters of s.
150 */
151 char *
152 strnstr(const char *s, const char *find, size_t slen)
153 {
154 char c, sc;
155 size_t len;
156
157 if ((c = *find++) != '\0') {
158 len = strlen(find);
159 do {
160 do {
161 if (slen-- < 1 || (sc = *s++) == '\0')
162 return (NULL);
163 } while (sc != c);
164 if (len > slen)
165 return (NULL);
166 } while (strncmp(s, find, len) != 0);
167 s--;
168 }
169 return ((char *)s);
170 }
171 #endif
172
173 #ifdef sun
174 #include <termios.h>
175 void cfmakeraw(struct termios *t) {
176 t->c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|
177 ISTRIP|INLCR|IGNCR|ICRNL|IXON);
178 t->c_oflag &= ~OPOST;
179 t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
180 t->c_cflag &= ~(CSIZE|PARENB);
181 t->c_cflag |= CS8;
182 }
183 #endif
184