ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/irc_string.c
Revision: 9331
Committed: Sat Apr 11 12:55:47 2020 UTC (6 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5431 byte(s)
Log Message:
- Remove strtok_r() compatibility code

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 9101 * Copyright (c) 1997-2020 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file irc_string.c
23     * \brief IRC string functions.
24     * \version $Id$
25     */
26    
27 michael 1009 #include "config.h"
28 adx 30 #include "stdinc.h"
29     #include "irc_string.h"
30    
31    
32 michael 8658 bool
33 michael 2883 has_wildcards(const char *str)
34 michael 1400 {
35 michael 2883 const unsigned char *p = (const unsigned char *)str;
36 michael 1400
37 michael 2883 for (; *p; ++p)
38     {
39     if (*p == '\\')
40     {
41     if (*++p == '\0')
42 michael 8658 return false;
43 michael 2883 }
44     else if (IsMWildChar(*p))
45 michael 8658 return true;
46 michael 2883 }
47 michael 1400
48 michael 8658 return false;
49 michael 1400 }
50    
51 michael 7797 const char *
52 michael 7726 stripws(char *txt)
53 adx 30 {
54 michael 7726 while (*txt == '\t' || *txt == ' ')
55     ++txt;
56 adx 30
57 michael 7726 char *tmp = txt + strlen(txt) - 1;
58     while (tmp >= txt && (*tmp == '\t' || *tmp == ' '))
59     --tmp;
60 adx 30
61 michael 7726 *(tmp + 1) = '\0';
62 adx 30
63 michael 7726 return txt;
64 adx 30 }
65    
66 michael 4309 /** Fill a vector of tokens from a delimited input list.
67     * Empty tokens (when \a token occurs at the start or end of \a list,
68     * or when \a token occurs adjacent to itself) are ignored. When
69     * \a size tokens have been written to \a vector, the rest of the
70     * string is ignored.
71     * \param names Input buffer.
72     * \param token Delimiter used to split \a list.
73     * \param vector Output vector.
74     * \param size Maximum number of elements to put in \a vector.
75     * \return Number of elements written to \a vector.
76     */
77 michael 7584 unsigned int
78     token_vector(char *names, char token, char *vector[], unsigned int size)
79 michael 4309 {
80 michael 7584 unsigned int count = 0;
81 michael 4309 char *start = names;
82    
83     assert(names);
84     assert(vector);
85     assert(size > 1);
86    
87     vector[count++] = start;
88    
89 michael 7584 for (char *end = strchr(start, token); end;
90     end = strchr(start, token))
91 michael 4309 {
92     *end++ = '\0';
93     start = end;
94    
95     if (*start)
96     {
97     vector[count++] = start;
98 michael 4915
99 michael 4309 if (count < size)
100     continue;
101     }
102    
103     break;
104     }
105    
106     return count;
107     }
108    
109 michael 978 /* libio_basename()
110 adx 30 *
111     * input - i.e. "/usr/local/ircd/modules/m_whois.so"
112     * output - i.e. "m_whois.so"
113     * side effects - this will be overwritten on subsequent calls
114     */
115 michael 978 const char *
116     libio_basename(const char *path)
117 adx 30 {
118 michael 978 const char *s;
119 adx 30
120     if ((s = strrchr(path, '/')) == NULL)
121     s = path;
122     else
123     s++;
124    
125     return s;
126     }
127    
128 michael 8161 /* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */
129     /* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */
130 adx 30 /*
131 michael 8161 * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
132 adx 30 *
133 michael 8161 * Permission to use, copy, modify, and distribute this software for any
134     * purpose with or without fee is hereby granted, provided that the above
135     * copyright notice and this permission notice appear in all copies.
136 adx 30 *
137 michael 8161 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
138     * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
139     * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
140     * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
141     * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
142     * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
143     * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
144 adx 30 */
145 michael 2916
146 adx 30 #ifndef HAVE_STRLCAT
147 michael 8161 /*
148     * Appends src to string dst of size dsize (unlike strncat, dsize is the
149     * full size of dst, not space left). At most dsize-1 characters
150     * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
151     * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
152     * If retval >= dsize, truncation occurred.
153     */
154 adx 30 size_t
155 michael 8161 strlcat(char *dst, const char *src, size_t dsize)
156 adx 30 {
157 michael 8161 const char *odst = dst;
158     const char *osrc = src;
159     size_t n = dsize;
160     size_t dlen;
161 adx 30
162 michael 8161 /* Find the end of dst and adjust bytes left but don't go past end. */
163     while (n-- != 0 && *dst != '\0')
164     dst++;
165 adx 30
166 michael 8161 dlen = dst - odst;
167     n = dsize - dlen;
168 adx 30
169 michael 8161 if (n-- == 0)
170     return dlen + strlen(src);
171 adx 30
172 michael 8161 while (*src != '\0')
173 adx 30 {
174 michael 8161 if (n != 0)
175 adx 30 {
176 michael 8161 *dst++ = *src;
177 adx 30 n--;
178     }
179    
180 michael 8161 src++;
181 adx 30 }
182    
183 michael 8161 *dst = '\0';
184    
185     return dlen + (src - osrc); /* count does not include NUL */
186 adx 30 }
187     #endif
188    
189     #ifndef HAVE_STRLCPY
190 michael 8161 /*
191     * Copy string src to buffer dst of size dsize. At most dsize-1
192     * chars will be copied. Always NUL terminates (unless dsize == 0).
193     * Returns strlen(src); if retval >= dsize, truncation occurred.
194     */
195 adx 30 size_t
196 michael 8161 strlcpy(char *dst, const char *src, size_t dsize)
197 adx 30 {
198 michael 8161 const char *osrc = src;
199     size_t nleft = dsize;
200 adx 30
201 michael 8161 /* Copy as many bytes as will fit. */
202     if (nleft != 0)
203 adx 30 {
204 michael 8161 while (--nleft != 0)
205 adx 30 {
206 michael 8161 if ((*dst++ = *src++) == '\0')
207 adx 30 break;
208 michael 8161 }
209 adx 30 }
210    
211 michael 8161 /* Not enough room in dst, add NUL and traverse rest of src. */
212     if (nleft == 0)
213 adx 30 {
214 michael 8161 if (dsize != 0)
215     *dst = '\0'; /* NUL-terminate dst */
216    
217     while (*src++)
218 adx 30 ;
219     }
220    
221 michael 8161 return src - osrc - 1; /* count does not include NUL */
222 adx 30 }
223     #endif

Properties

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