ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/string.C
(Generate patch)

Comparing ermyth/src/string.C (file contents):
Revision 1.3 by pippijn, Sat Jul 21 13:23:22 2007 UTC vs.
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC

3 * Rights to this code are documented in doc/pod/license.pod. 3 * Rights to this code are documented in doc/pod/license.pod.
4 * 4 *
5 * String functions. 5 * String functions.
6 */ 6 */
7 7
8static char const rcsid[] = "$Id: string.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; 8static char const rcsid[] = "$Id: string.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $";
9
10#include <algorithm>
11 9
12#include "atheme.h" 10#include "atheme.h"
11
12char *
13sstrdup (char const * const s)
14{
15 char *t;
16 size_t len;
17
18 if (s == NULL)
19 return NULL;
20
21 t = alloc<char> (len = strlen (s) + 1);
22
23 strlcpy (t, s, len);
24 return t;
25}
26
27char *
28sstrndup (char const *s, int len)
29{
30 char *t;
31
32 if (s == NULL)
33 return NULL;
34
35 t = alloc<char> (len + 1);
36
37 strlcpy (t, s, len);
38 return t;
39}
13 40
14void 41void
15assign (char *dst, char const *src, size_t maxlen) 42assign (char *dst, char const *src, size_t maxlen)
16{ 43{
17 if (!src) 44 if (!src)
89 116
90 return c; 117 return c;
91} 118}
92 119
93int 120int
94string::append (char c) 121dynstr::append (char c)
95{ 122{
96 if (size - pos <= 1) 123 if (size - pos <= 1)
97 { 124 {
98 size_t new_size = std::max (size * 2, pos + 9); 125 size_t new_size = std::max (size * 2, pos + 9);
99 size = new_size; 126 size = new_size;
104 131
105 return size; 132 return size;
106} 133}
107 134
108int 135int
109string::append_nonul (char c) 136dynstr::append_nonul (char c)
110{ 137{
111 if (size - pos <= 1) 138 if (size - pos <= 1)
112 { 139 {
113 size_t new_size = std::max (size * 2, pos + 9); 140 size_t new_size = std::max (size * 2, pos + 9);
114 size = new_size; 141 size = new_size;
118 145
119 return size; 146 return size;
120} 147}
121 148
122int 149int
123string::append (char const *src, size_t size) 150dynstr::append (char const *src, size_t len)
124{ 151{
125 if (this->size - pos <= size) 152 if (size - pos <= len)
126 { 153 {
127 size_t new_size = std::max (this->size * 2, pos + size + 8); 154 size_t new_size = std::max (size * 2, pos + len + 8);
128 this->size = new_size; 155 size = new_size;
129 m_rep = new char[new_size]; 156 m_rep = new char[new_size];
130 } 157 }
131 memcpy (m_rep + pos, src, size); 158 memcpy (m_rep + pos, src, len);
132 pos += size; 159 pos += len;
133 m_rep[pos] = '\0'; 160 m_rep[pos] = '\0';
134 161
135 return size; 162 return len;
136} 163}
137 164
138int 165int
139string::append_nonul (char const *src, size_t size) 166dynstr::append_nonul (char const *src, size_t len)
140{ 167{
141 if (this->size - pos <= size) 168 if (size - pos <= len)
142 { 169 {
143 size_t new_size = std::max (this->size * 2, pos + size + 8); 170 size_t new_size = std::max (size * 2, pos + len + 8);
144 this->size = new_size; 171 size = new_size;
145 m_rep = new char[new_size]; 172 m_rep = new char[new_size];
146 } 173 }
147 memcpy (m_rep + pos, src, size); 174 memcpy (m_rep + pos, src, len);
148 pos += size; 175 pos += len;
149 176
150 return size; 177 return len;
151} 178}
152 179
153int 180int
154string::append_unguarded (char c) 181dynstr::append_unguarded (char c)
155{ 182{
156 m_rep[pos] = c; 183 m_rep[pos] = c;
157 m_rep[++pos] = '\0'; 184 m_rep[++pos] = '\0';
158 185
159 return size; 186 return size;
160} 187}
161 188
162int 189int
163string::append_unguarded_nonul (char c) 190dynstr::append_unguarded_nonul (char c)
164{ 191{
165 m_rep[pos++] = c; 192 m_rep[pos++] = c;
166 193
167 return size; 194 return size;
168} 195}
169 196
170int 197int
171string::append_unguarded (char const *src, size_t size) 198dynstr::append_unguarded (char const *src, size_t len)
172{ 199{
173 memcpy (m_rep + pos, src, size); 200 memcpy (m_rep + pos, src, len);
174 pos += size; 201 pos += len;
175 m_rep[pos] = '\0'; 202 m_rep[pos] = '\0';
176 203
177 return size; 204 return len;
178} 205}
179 206
180int 207int
181string::append_unguarded_nonul (char const *src, size_t size) 208dynstr::append_unguarded_nonul (char const *src, size_t len)
182{ 209{
183 memcpy (m_rep + pos, src, size); 210 memcpy (m_rep + pos, src, len);
184 pos += size; 211 pos += len;
185 212
186 return size; 213 return len;
187} 214}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines