ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/irc_string.c
Revision: 3246
Committed: Sun Mar 30 17:37:13 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 5399 byte(s)
Log Message:
- Fixed inconsistent style in several places

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 2916 * Copyright (c) 1997-2014 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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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 1400 int
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     return 0;
43     }
44     else if (IsMWildChar(*p))
45 michael 1400 return 1;
46 michael 2883 }
47 michael 1400
48     return 0;
49     }
50    
51 adx 30 /*
52     * strip_tabs(dst, src, length)
53     *
54     * Copies src to dst, while converting all \t (tabs) into spaces.
55     */
56     void
57     strip_tabs(char *dest, const char *src, size_t len)
58     {
59     char *d = dest;
60    
61     /* Sanity check; we don't want anything nasty... */
62 michael 3246 assert(dest);
63     assert(src);
64 adx 30 assert(len > 0);
65    
66     for (; --len && *src; ++src)
67     *d++ = *src == '\t' ? ' ' : *src;
68    
69     *d = '\0'; /* NUL terminate, thanks and goodbye */
70     }
71    
72     /*
73     * strtoken - walk through a string of tokens, using a set of separators
74     * argv 9/90
75     *
76     */
77     #ifndef HAVE_STRTOK_R
78     char *
79     strtoken(char** save, char* str, const char* fs)
80     {
81     char* pos = *save; /* keep last position across calls */
82     char* tmp;
83    
84     if (str)
85     pos = str; /* new string scan */
86    
87 michael 3246 while (pos && *pos && strchr(fs, *pos))
88 adx 30 ++pos; /* skip leading separators */
89    
90     if (!pos || !*pos)
91     return (pos = *save = NULL); /* string contains only sep's */
92    
93     tmp = pos; /* now, keep position of the token */
94    
95     while (*pos && strchr(fs, *pos) == NULL)
96     ++pos; /* skip content of the token */
97    
98     if (*pos)
99     *pos++ = '\0'; /* remove first sep after the token */
100     else
101     pos = NULL; /* end of string */
102    
103     *save = pos;
104     return tmp;
105     }
106     #endif /* !HAVE_STRTOK_R */
107    
108 michael 978 /* libio_basename()
109 adx 30 *
110     * input - i.e. "/usr/local/ircd/modules/m_whois.so"
111     * output - i.e. "m_whois.so"
112     * side effects - this will be overwritten on subsequent calls
113     */
114 michael 978 const char *
115     libio_basename(const char *path)
116 adx 30 {
117 michael 978 const char *s;
118 adx 30
119     if ((s = strrchr(path, '/')) == NULL)
120     s = path;
121     else
122     s++;
123    
124     return s;
125     }
126    
127     /*
128     * strlcat and strlcpy were ripped from openssh 2.5.1p2
129 michael 2916 * They had the following Copyright info:
130 adx 30 *
131     *
132     * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
133     * All rights reserved.
134     *
135     * Redistribution and use in source and binary forms, with or without
136     * modification, are permitted provided that the following conditions
137     * are met:
138     * 1. Redistributions of source code must retain the above copyright
139     * notice, this list of conditions and the following disclaimer.
140 michael 2916 * 2. Redistributions in binary form must reproduce the above copyright
141     * notice, this list of conditions and the following disclaimer in the
142     * documentation and/or other materials provided with the distribution.
143 adx 30 * 3. The name of the author may not be used to endorse or promote products
144     * derived from this software without specific prior written permission.
145     *
146     * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
147     * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
148     * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
149     * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
150     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
151     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
152     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
153     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
154     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
155     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156     */
157 michael 2916
158 adx 30 #ifndef HAVE_STRLCAT
159     size_t
160     strlcat(char *dst, const char *src, size_t siz)
161     {
162     char *d = dst;
163     const char *s = src;
164     size_t n = siz, dlen;
165    
166     while (n-- != 0 && *d != '\0')
167     d++;
168    
169     dlen = d - dst;
170     n = siz - dlen;
171    
172     if (n == 0)
173 michael 1122 return dlen + strlen(s);
174 adx 30
175     while (*s != '\0')
176     {
177     if (n != 1)
178     {
179     *d++ = *s;
180     n--;
181     }
182    
183     s++;
184     }
185    
186     *d = '\0';
187     return dlen + (s - src); /* count does not include NUL */
188     }
189     #endif
190    
191     #ifndef HAVE_STRLCPY
192     size_t
193     strlcpy(char *dst, const char *src, size_t siz)
194     {
195     char *d = dst;
196     const char *s = src;
197     size_t n = siz;
198    
199     /* Copy as many bytes as will fit */
200     if (n != 0 && --n != 0)
201     {
202     do
203     {
204     if ((*d++ = *s++) == 0)
205     break;
206     } while (--n != 0);
207     }
208    
209     /* Not enough room in dst, add NUL and traverse rest of src */
210     if (n == 0)
211     {
212     if (siz != 0)
213     *d = '\0'; /* NUL-terminate dst */
214     while (*s++)
215     ;
216     }
217    
218     return s - src - 1; /* count does not include NUL */
219     }
220     #endif

Properties

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