ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/irc_string.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/irc_string.c (file contents):
Revision 2883 by michael, Mon Jan 20 18:17:57 2014 UTC vs.
Revision 7668 by michael, Wed Jul 20 17:09:49 2016 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  irc_string.c: IRC string functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
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
# Line 16 | Line 15
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
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file irc_string.c
23 > * \brief IRC string functions.
24 > * \version $Id$
25   */
26  
27   #include "config.h"
# Line 47 | Line 49 | has_wildcards(const char *str)
49   }
50  
51   /*
50 * myctime - This is like standard ctime()-function, but it zaps away
51 *   the newline from the end of that string. Also, it takes
52 *   the time value as parameter, instead of pointer to it.
53 *   Note that it is necessary to copy the string to alternate
54 *   buffer (who knows how ctime() implements it, maybe it statically
55 *   has newline there and never 'refreshes' it -- zapping that
56 *   might break things in other places...)
57 *
58 *
59 * Thu Nov 24 18:22:48 1986
60 */
61 const char *
62 myctime(time_t value)
63 {
64  static char buf[32];
65  char *p;
66
67  strlcpy(buf, ctime(&value), sizeof(buf));
68
69  if ((p = strchr(buf, '\n')) != NULL)
70    *p = '\0';
71  return buf;
72 }
73
74 /*
52   * strip_tabs(dst, src, length)
53   *
54   *   Copies src to dst, while converting all \t (tabs) into spaces.
# Line 82 | Line 59 | strip_tabs(char *dest, const char *src,
59    char *d = dest;
60  
61    /* Sanity check; we don't want anything nasty... */
62 <  assert(dest != NULL);
63 <  assert(src  != NULL);
62 >  assert(dest);
63 >  assert(src);
64    assert(len > 0);
65  
66    for (; --len && *src; ++src)
# Line 93 | Line 70 | strip_tabs(char *dest, const char *src,
70   }
71  
72   /*
73 < * strtoken - walk through a string of tokens, using a set of separators
73 > * strtok_r - walk through a string of tokens, using a set of separators
74   *   argv 9/90
75   *
76   */
77   #ifndef HAVE_STRTOK_R
101
78   char *
79 < strtoken(char** save, char* str, const char* fs)
79 > strtok_r(char *str, const char *fs, char **save)
80   {
81 <  char* pos = *save;  /* keep last position across calls */
82 <  char* tmp;
81 >  char *pos = *save;  /* keep last position across calls */
82 >  char *tmp = NULL;
83  
84    if (str)
85      pos = str;    /* new string scan */
86  
87 <  while (pos && *pos && strchr(fs, *pos) != NULL)
87 >  while (pos && *pos && strchr(fs, *pos))
88      ++pos;        /* skip leading separators */
89  
90    if (!pos || !*pos)
91 <    return (pos = *save = NULL);   /* string contains only sep's */
91 >    return pos = *save = NULL;   /* string contains only sep's */
92  
93    tmp = pos;       /* now, keep position of the token */
94  
# Line 129 | Line 105 | strtoken(char** save, char* str, const c
105   }
106   #endif /* !HAVE_STRTOK_R */
107  
108 + /** Fill a vector of tokens from a delimited input list.
109 + * Empty tokens (when \a token occurs at the start or end of \a list,
110 + * or when \a token occurs adjacent to itself) are ignored.  When
111 + * \a size tokens have been written to \a vector, the rest of the
112 + * string is ignored.
113 + * \param names Input buffer.
114 + * \param token Delimiter used to split \a list.
115 + * \param vector Output vector.
116 + * \param size Maximum number of elements to put in \a vector.
117 + * \return Number of elements written to \a vector.
118 + */
119 + unsigned int
120 + token_vector(char *names, char token, char *vector[], unsigned int size)
121 + {
122 +  unsigned int count = 0;
123 +  char *start = names;
124 +
125 +  assert(names);
126 +  assert(vector);
127 +  assert(size > 1);
128 +
129 +  vector[count++] = start;
130 +
131 +  for (char *end = strchr(start, token); end;
132 +             end = strchr(start, token))
133 +  {
134 +    *end++ = '\0';
135 +    start = end;
136 +
137 +    if (*start)
138 +    {
139 +      vector[count++] = start;
140 +
141 +      if (count < size)
142 +        continue;
143 +    }
144 +
145 +    break;
146 +  }
147 +
148 +  return count;
149 + }
150 +
151   /* libio_basename()
152   *
153   * input        - i.e. "/usr/local/ircd/modules/m_whois.so"
# Line 150 | Line 169 | libio_basename(const char *path)
169  
170   /*
171   * strlcat and strlcpy were ripped from openssh 2.5.1p2
172 < * They had the following Copyright info:
172 > * They had the following Copyright info:
173   *
174   *
175   * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
# Line 161 | Line 180 | libio_basename(const char *path)
180   * are met:
181   * 1. Redistributions of source code must retain the above copyright
182   *    notice, this list of conditions and the following disclaimer.
183 < * 2. Redistributions in binary form must reproduce the above copyright    
184 < *    notice, this list of conditions and the following disclaimer in the  
185 < *    documentation and/or other materials provided with the distribution.
183 > * 2. Redistributions in binary form must reproduce the above copyright
184 > *    notice, this list of conditions and the following disclaimer in the
185 > *    documentation and/or other materials provided with the distribution.
186   * 3. The name of the author may not be used to endorse or promote products
187   *    derived from this software without specific prior written permission.
188   *
# Line 178 | Line 197 | libio_basename(const char *path)
197   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
198   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199   */
200 <
200 >
201   #ifndef HAVE_STRLCAT
202   size_t
203   strlcat(char *dst, const char *src, size_t siz)

Comparing ircd-hybrid/trunk/src/irc_string.c (property svn:keywords):
Revision 2883 by michael, Mon Jan 20 18:17:57 2014 UTC vs.
Revision 7668 by michael, Wed Jul 20 17:09:49 2016 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)