ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/irc_string.c
Revision: 2916
Committed: Sat Jan 25 21:09:18 2014 UTC (12 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 6085 byte(s)
Log Message:
- Clean up all files in include/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years

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

Properties

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