1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: strings.c |
2 | * File: strings.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: strings.C,v 1.5 2004/02/13 12:16:21 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> |
6 | * Copyright (c) 1997-2001 Geoff Wing <gcw@pobox.com> |
|
|
7 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
12 | * (at your option) any later version. |
… | |
… | |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | *----------------------------------------------------------------------*/ |
22 | *----------------------------------------------------------------------*/ |
23 | |
23 | |
24 | #include "../config.h" /* NECESSARY */ |
24 | #include "../config.h" /* NECESSARY */ |
25 | #include "rxvt.h" /* NECESSARY */ |
25 | #include "rxvt.h" /* NECESSARY */ |
26 | #include "strings.intpro" /* PROTOS for internal routines */ |
|
|
27 | |
26 | |
28 | #ifndef NO_STRINGS |
27 | #ifndef NO_STRINGS |
29 | /*----------------------------------------------------------------------*/ |
28 | /*----------------------------------------------------------------------*/ |
30 | /* |
29 | /* |
31 | * a replacement for strcasecmp () to avoid linking an entire library. |
30 | * a replacement for strcasecmp () to avoid linking an entire library. |
… | |
… | |
132 | } |
131 | } |
133 | |
132 | |
134 | char * |
133 | char * |
135 | strdup (const char *s) |
134 | strdup (const char *s) |
136 | { |
135 | { |
137 | size_t len = STRLEN (s) + 1; |
136 | size_t len = strlen (s) + 1; |
138 | char *c; |
137 | char *c; |
139 | |
138 | |
140 | if ((c = malloc (len)) != NULL) |
139 | if ((c = malloc (len)) != NULL) |
141 | MEMCPY (c, s, len); |
140 | memcpy (c, s, len); |
142 | return c; |
141 | return c; |
143 | } |
142 | } |
144 | |
143 | |
145 | char * |
144 | char * |
146 | index (const char *s, int c) |
145 | index (const char *s, int c) |
147 | { |
146 | { |
148 | return STRCHR (s, c); |
147 | return strchr (s, c); |
149 | } |
148 | } |
150 | |
149 | |
151 | char * |
150 | char * |
152 | strchr (const char *s, int c) |
151 | strchr (const char *s, int c) |
153 | { |
152 | { |
… | |
… | |
168 | } |
167 | } |
169 | |
168 | |
170 | char * |
169 | char * |
171 | rindex (const char *s, int c) |
170 | rindex (const char *s, int c) |
172 | { |
171 | { |
173 | return STRRCHR (s, c); |
172 | return strrchr (s, c); |
174 | } |
173 | } |
175 | |
174 | |
176 | char * |
175 | char * |
177 | strrchr (const char *s, int c) |
176 | strrchr (const char *s, int c) |
178 | { |
177 | { |
… | |
… | |
190 | |
189 | |
191 | void * |
190 | void * |
192 | memcpy (void *s1, const void *s2, size_t len) |
191 | memcpy (void *s1, const void *s2, size_t len) |
193 | { |
192 | { |
194 | /* has extra stack and time but less code space */ |
193 | /* has extra stack and time but less code space */ |
195 | return MEMMOVE (s1, s2, len); |
194 | return memmove (s1, s2, len); |
196 | } |
195 | } |
197 | |
196 | |
198 | /*--------------------------------------------------------------------------* |
197 | /*--------------------------------------------------------------------------* |
199 | * Possibly faster memmove () by Geoff Wing <mason@primenet.com.au> |
198 | * Possibly faster memmove () by Geoff Wing <mason@primenet.com.au> |
200 | *--------------------------------------------------------------------------*/ |
199 | *--------------------------------------------------------------------------*/ |
… | |
… | |
255 | *--------------------------------------------------------------------------*/ |
254 | *--------------------------------------------------------------------------*/ |
256 | |
255 | |
257 | void |
256 | void |
258 | bzero (void *b, size_t len) |
257 | bzero (void *b, size_t len) |
259 | { |
258 | { |
260 | MEMSET (b, 0, len); |
259 | memset (b, 0, len); |
261 | } |
260 | } |
262 | |
261 | |
263 | void * |
262 | void * |
264 | memset (void *p, int c1, size_t len) |
263 | memset (void *p, int c1, size_t len) |
265 | { |
264 | { |