2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Tridgell 1992-2001
5 Copyright (C) Simo Sorce 2001-2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /****************************************************************************
25 Get the next token from a string, return False if none found
26 handles double-quotes.
27 Based on a routine by GJC@VILLAGE.COM.
28 Extensively modified by Andrew.Tridgell@anu.edu.au
29 ****************************************************************************/
30 BOOL next_token(char **ptr,char *buff,char *sep, size_t bufsize)
36 if (!ptr) return(False);
40 /* default to simple separators */
41 if (!sep) sep = " \t\n\r";
43 /* find the first non sep char */
44 while (*s && strchr_m(sep,*s)) s++;
47 if (! *s) return(False);
49 /* copy over the token */
50 for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) {
59 *ptr = (*s) ? s+1 : s;
67 /****************************************************************************
68 This is like next_token but is not re-entrant and "remembers" the first
69 parameter so you can pass NULL. This is useful for user interface code
70 but beware the fact that it is not re-entrant!
71 ****************************************************************************/
72 static char *last_ptr=NULL;
74 BOOL next_token_nr(char **ptr,char *buff,char *sep, size_t bufsize)
77 if (!ptr) ptr = &last_ptr;
79 ret = next_token(ptr, buff, sep, bufsize);
84 static uint16 tmpbuf[sizeof(pstring)];
86 void set_first_token(char *ptr)
92 /****************************************************************************
93 Convert list of tokens to array; dependent on above routine.
94 Uses last_ptr from above - bit of a hack.
95 ****************************************************************************/
96 char **toktocliplist(int *ctok, char *sep)
102 if (!sep) sep = " \t\n\r";
104 while(*s && strchr_m(sep,*s)) s++;
107 if (!*s) return(NULL);
111 while(*s && (!strchr_m(sep,*s))) s++;
112 while(*s && strchr_m(sep,*s)) *s++=0;
118 if (!(ret=iret=malloc(ictok*sizeof(char *)))) return NULL;
129 /*******************************************************************
130 case insensitive string compararison
131 ********************************************************************/
132 int StrCaseCmp(const char *s, const char *t)
135 unix_strupper(s, strlen(s)+1, buf1, sizeof(buf1));
136 unix_strupper(t, strlen(t)+1, buf2, sizeof(buf2));
137 return strcmp(buf1,buf2);
140 /*******************************************************************
141 case insensitive string compararison, length limited
142 ********************************************************************/
143 int StrnCaseCmp(const char *s, const char *t, size_t n)
146 unix_strupper(s, strlen(s)+1, buf1, sizeof(buf1));
147 unix_strupper(t, strlen(t)+1, buf2, sizeof(buf2));
148 return strncmp(buf1,buf2,n);
151 /*******************************************************************
153 ********************************************************************/
154 BOOL strequal(const char *s1, const char *s2)
156 if (s1 == s2) return(True);
157 if (!s1 || !s2) return(False);
159 return(StrCaseCmp(s1,s2)==0);
162 /*******************************************************************
163 compare 2 strings up to and including the nth char.
164 ******************************************************************/
165 BOOL strnequal(const char *s1,const char *s2,size_t n)
167 if (s1 == s2) return(True);
168 if (!s1 || !s2 || !n) return(False);
170 return(StrnCaseCmp(s1,s2,n)==0);
173 /*******************************************************************
174 compare 2 strings (case sensitive)
175 ********************************************************************/
176 BOOL strcsequal(const char *s1,const char *s2)
178 if (s1 == s2) return(True);
179 if (!s1 || !s2) return(False);
181 return(strcmp(s1,s2)==0);
184 /***************************************************************************
185 Do a case-insensitive, whitespace-ignoring string compare.
186 ***************************************************************************/
187 int strwicmp(const char *psz1, const char *psz2)
189 /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
190 /* appropriate value. */
193 else if (psz1 == NULL)
195 else if (psz2 == NULL)
198 /* sync the strings on first non-whitespace */
201 while (isspace((int)*psz1))
203 while (isspace((int)*psz2))
205 if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0'
211 return (*psz1 - *psz2);
215 /*******************************************************************
216 convert a string to "normal" form
217 ********************************************************************/
218 void strnorm(char *s)
220 extern int case_default;
221 if (case_default == CASE_UPPER)
227 /*******************************************************************
228 check if a string is in "normal" case
229 ********************************************************************/
230 BOOL strisnormal(char *s)
232 extern int case_default;
233 if (case_default == CASE_UPPER)
234 return(!strhaslower(s));
236 return(!strhasupper(s));
240 /****************************************************************************
242 NOTE: oldc and newc must be 7 bit characters
243 ****************************************************************************/
244 void string_replace(char *s,char oldc,char newc)
246 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
247 string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
248 pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
252 /*******************************************************************
253 skip past some strings in a buffer
254 ********************************************************************/
255 char *skip_string(char *buf,size_t n)
258 buf += strlen(buf) + 1;
262 /*******************************************************************
263 Count the number of characters in a string. Normally this will
264 be the same as the number of bytes in a string for single byte strings,
265 but will be different for multibyte.
266 ********************************************************************/
267 size_t str_charnum(const char *s)
269 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
270 return strlen_w(tmpbuf);
273 /*******************************************************************
274 trim the specified elements off the front and back of a string
275 ********************************************************************/
277 BOOL trim_string(char *s,const char *front,const char *back)
284 /* Ignore null or empty strings. */
285 if (!s || (s[0] == '\0'))
288 front_len = front? strlen(front) : 0;
289 back_len = back? strlen(back) : 0;
294 while (len && strncmp(s, front, front_len)==0) {
295 memcpy(s, s+front_len, (len-front_len)+1);
302 while ((len >= back_len) && strncmp(s+len-back_len,back,back_len)==0) {
303 s[len-back_len]='\0';
312 /****************************************************************************
313 does a string have any uppercase chars in it?
314 ****************************************************************************/
315 BOOL strhasupper(const char *s)
318 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
319 for(ptr=tmpbuf;*ptr;ptr++)
320 if(isupper_w(*ptr)) return True;
324 /****************************************************************************
325 does a string have any lowercase chars in it?
326 ****************************************************************************/
327 BOOL strhaslower(const char *s)
330 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
331 for(ptr=tmpbuf;*ptr;ptr++)
332 if(islower_w(*ptr)) return True;
336 /****************************************************************************
337 find the number of 'c' chars in a string
338 ****************************************************************************/
339 size_t count_chars(const char *s,char c)
343 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
344 for(count=0,ptr=tmpbuf;*ptr;ptr++) if(*ptr==UCS2_CHAR(c)) count++;
348 /*******************************************************************
349 Return True if a string consists only of one particular character.
350 ********************************************************************/
352 BOOL str_is_all(const char *s,char c)
356 if(s == NULL) return False;
357 if(!*s) return False;
359 push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
360 for(ptr=tmpbuf;*ptr;ptr++) if(*ptr!=UCS2_CHAR(c)) return False;
365 /*******************************************************************
366 safe string copy into a known length string. maxlength does not
367 include the terminating zero.
368 ********************************************************************/
370 char *safe_strcpy(char *dest,const char *src, size_t maxlength)
375 DEBUG(0,("ERROR: NULL dest in safe_strcpy\n"));
386 if (len > maxlength) {
387 DEBUG(0,("ERROR: string overflow by %d in safe_strcpy [%.50s]\n",
388 (int)(len-maxlength), src));
392 memmove(dest, src, len);
397 /*******************************************************************
398 safe string cat into a string. maxlength does not
399 include the terminating zero.
400 ********************************************************************/
402 char *safe_strcat(char *dest, const char *src, size_t maxlength)
404 size_t src_len, dest_len;
407 DEBUG(0,("ERROR: NULL dest in safe_strcat\n"));
415 src_len = strlen(src);
416 dest_len = strlen(dest);
418 if (src_len + dest_len > maxlength) {
419 DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n",
420 (int)(src_len + dest_len - maxlength), src));
421 src_len = maxlength - dest_len;
424 memcpy(&dest[dest_len], src, src_len);
425 dest[dest_len + src_len] = 0;
429 /*******************************************************************
430 Paranoid strcpy into a buffer of given length (includes terminating
431 zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
432 and replaces with '_'. Deliberately does *NOT* check for multibyte
433 characters. Don't change it !
434 ********************************************************************/
436 char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
441 DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
451 if (len >= maxlength)
454 if (!other_safe_chars)
455 other_safe_chars = "";
457 for(i = 0; i < len; i++) {
458 int val = (src[i] & 0xff);
459 if(isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val))
470 /****************************************************************************
471 Like strncpy but always null terminates. Make sure there is room!
472 The variable n should always be one less than the available size.
473 ****************************************************************************/
475 char *StrnCpy(char *dest,const char *src,size_t n)
478 if (!dest) return(NULL);
483 while (n-- && (*d++ = *src++)) ;
488 /****************************************************************************
489 like strncpy but copies up to the character marker. always null terminates.
490 returns a pointer to the character marker in the source string (src).
491 ****************************************************************************/
492 char *strncpyn(char *dest, const char *src,size_t n, char c)
497 p = strchr_m(src, c);
500 DEBUG(5, ("strncpyn: separator character (%c) not found\n", c));
504 str_len = PTR_DIFF(p, src);
505 strncpy(dest, src, MIN(n, str_len));
506 dest[str_len] = '\0';
512 /*************************************************************
513 Routine to get hex characters and turn them into a 16 byte array.
514 the array can be variable length, and any non-hex-numeric
515 characters are skipped. "0xnn" or "0Xnn" is specially catered
518 valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
520 **************************************************************/
521 size_t strhex_to_str(char *p, size_t len, const char *strhex)
524 size_t num_chars = 0;
525 unsigned char lonybble, hinybble;
526 char *hexchars = "0123456789ABCDEF";
527 char *p1 = NULL, *p2 = NULL;
529 for (i = 0; i < len && strhex[i] != 0; i++)
531 if (strnequal(hexchars, "0x", 2))
533 i++; /* skip two chars */
537 if (!(p1 = strchr_m(hexchars, toupper(strhex[i]))))
542 i++; /* next hex digit */
544 if (!(p2 = strchr_m(hexchars, toupper(strhex[i]))))
549 /* get the two nybbles */
550 hinybble = PTR_DIFF(p1, hexchars);
551 lonybble = PTR_DIFF(p2, hexchars);
553 p[num_chars] = (hinybble << 4) | lonybble;
562 /****************************************************************************
563 check if a string is part of a list
564 ****************************************************************************/
565 BOOL in_list(char *s,char *list,BOOL casesensitive)
570 if (!list) return(False);
572 while (next_token(&p,tok,LIST_SEP,sizeof(tok))) {
574 if (strcmp(tok,s) == 0)
577 if (StrCaseCmp(tok,s) == 0)
584 /* this is used to prevent lots of mallocs of size 1 */
585 static char *null_string = NULL;
587 /****************************************************************************
588 set a string value, allocing the space for the string
589 ****************************************************************************/
590 static BOOL string_init(char **dest,const char *src)
601 if((null_string = (char *)malloc(1)) == NULL) {
602 DEBUG(0,("string_init: malloc fail for null_string.\n"));
611 (*dest) = (char *)malloc(l+1);
612 if ((*dest) == NULL) {
613 DEBUG(0,("Out of memory in string_init\n"));
622 /****************************************************************************
624 ****************************************************************************/
625 void string_free(char **s)
627 if (!s || !(*s)) return;
628 if (*s == null_string)
633 /****************************************************************************
634 set a string value, allocing the space for the string, and deallocating any
636 ****************************************************************************/
637 BOOL string_set(char **dest,const char *src)
641 return(string_init(dest,src));
645 /****************************************************************************
646 substitute a string for a pattern in another string. Make sure there is
649 This routine looks for pattern in s and replaces it with
650 insert. It may do multiple replacements.
652 any of " ; ' $ or ` in the insert string are replaced with _
653 if len==0 then the string cannot be extended. This is different from the old
654 use of len==0 which was for no length checks to be done.
655 ****************************************************************************/
657 void string_sub(char *s,const char *pattern, const char *insert, size_t len)
662 if (!insert || !pattern || !*pattern || !s)
665 ls = (ssize_t)strlen(s);
666 lp = (ssize_t)strlen(pattern);
667 li = (ssize_t)strlen(insert);
670 len = ls + 1; /* len is number of *bytes* */
672 while (lp <= ls && (p = strstr(s,pattern))) {
673 if (ls + (li-lp) >= len) {
674 DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n",
675 (int)(ls + (li-lp) - len),
680 memmove(p+li,p+lp,strlen(p+lp)+1);
703 void fstring_sub(char *s,const char *pattern,const char *insert)
705 string_sub(s, pattern, insert, sizeof(fstring));
708 void pstring_sub(char *s,const char *pattern,const char *insert)
710 string_sub(s, pattern, insert, sizeof(pstring));
713 /* similar to string_sub, but it will accept only allocated strings
714 * and may realloc them so pay attention at what you pass on no
715 * pointers inside strings, no pstrings or const must be passed
719 char *realloc_string_sub(char *string, const char *pattern, const char *insert)
723 ssize_t ls,lp,li,ld, i;
725 if (!insert || !pattern || !*pattern || !string || !*string)
732 DEBUG(0, ("realloc_string_sub: out of memory!\n"));
735 ls = (ssize_t)strlen(s);
736 lp = (ssize_t)strlen(pattern);
737 li = (ssize_t)strlen(insert);
756 while ((p = strstr(s,pattern))) {
758 char *t = Realloc(string, ls + ld + 1);
760 DEBUG(0, ("realloc_string_sub: out of memory!\n"));
768 memmove(p+li,p+lp,strlen(p+lp)+1);
778 /****************************************************************************
779 similar to string_sub() but allows for any character to be substituted.
781 if len==0 then the string cannot be extended. This is different from the old
782 use of len==0 which was for no length checks to be done.
783 ****************************************************************************/
785 void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
790 if (!insert || !pattern || !s)
793 ls = (ssize_t)strlen(s);
794 lp = (ssize_t)strlen(pattern);
795 li = (ssize_t)strlen(insert);
801 len = ls + 1; /* len is number of *bytes* */
803 while (lp <= ls && (p = strstr(s,pattern))) {
804 if (ls + (li-lp) >= len) {
805 DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n",
806 (int)(ls + (li-lp) - len),
811 memmove(p+li,p+lp,strlen(p+lp)+1);
813 memcpy(p, insert, li);
819 /****************************************************************************
820 similar to all_string_sub but for unicode strings.
821 return a new allocate unicode string.
822 similar to string_sub() but allows for any character to be substituted.
824 ****************************************************************************/
826 smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *pattern,
827 const smb_ucs2_t *insert)
830 const smb_ucs2_t *sp;
831 size_t lr, lp, li, lt;
833 if (!insert || !pattern || !*pattern || !s) return NULL;
835 lt = (size_t)strlen_w(s);
836 lp = (size_t)strlen_w(pattern);
837 li = (size_t)strlen_w(insert);
840 const smb_ucs2_t *st = s;
842 while ((sp = strstr_w(st, pattern))) {
848 r = rp = (smb_ucs2_t *)malloc((lt + 1)*(sizeof(smb_ucs2_t)));
850 DEBUG(0, ("all_string_sub_w: out of memory!\n"));
854 while ((sp = strstr_w(s, pattern))) {
855 memcpy(rp, s, (sp - s));
856 rp += ((sp - s) / sizeof(smb_ucs2_t));
857 memcpy(rp, insert, (li * sizeof(smb_ucs2_t)));
861 lr = ((rp - r) / sizeof(smb_ucs2_t));
863 memcpy(rp, s, ((lt - lr) * sizeof(smb_ucs2_t)));
871 smb_ucs2_t *all_string_sub_wa(smb_ucs2_t *s, const char *pattern,
876 if (!insert || !pattern || !s) return NULL;
877 push_ucs2(NULL, p, pattern, sizeof(wpstring) - 1, STR_TERMINATE);
878 push_ucs2(NULL, i, insert, sizeof(wpstring) - 1, STR_TERMINATE);
879 return all_string_sub_w(s, p, i);
882 /****************************************************************************
883 Splits out the front and back at a separator.
884 ****************************************************************************/
886 void split_at_last_component(char *path, char *front, char sep, char *back)
888 char *p = strrchr_m(path, sep);
894 pstrcpy(front, path);
906 /****************************************************************************
907 Write an octal as a string.
908 ****************************************************************************/
910 char *octal_string(int i)
915 slprintf(ret, sizeof(ret)-1, "0%o", i);
920 /****************************************************************************
921 Truncate a string at a specified length.
922 ****************************************************************************/
924 char *string_truncate(char *s, int length)
926 if (s && strlen(s) > length)
931 /****************************************************************************
932 Strchr and strrchr_m are very hard to do on general multi-byte strings.
933 We convert via ucs2 for now.
934 ****************************************************************************/
936 char *strchr_m(const char *s, char c)
942 push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
943 p = strchr_w(ws, UCS2_CHAR(c));
947 pull_ucs2_pstring(s2, ws);
948 return (char *)(s+strlen(s2));
951 char *strrchr_m(const char *s, char c)
957 push_ucs2(NULL, ws, s, sizeof(ws), STR_TERMINATE);
958 p = strrchr_w(ws, UCS2_CHAR(c));
962 pull_ucs2_pstring(s2, ws);
963 return (char *)(s+strlen(s2));
966 /*******************************************************************
967 Convert a string to lower case.
968 ********************************************************************/
970 void strlower_m(char *s)
972 /* this is quite a common operation, so we want it to be
973 fast. We optimise for the ascii case, knowing that all our
974 supported multi-byte character sets are ascii-compatible
975 (ie. they match for the first 128 chars) */
977 while (*s && !(((unsigned char)s[0]) & 0x7F))
978 *s++ = tolower((unsigned char)*s);
983 /* I assume that lowercased string takes the same number of bytes
984 * as source string even in UTF-8 encoding. (VIV) */
985 unix_strlower(s,strlen(s)+1,s,strlen(s)+1);
988 /*******************************************************************
989 Duplicate convert a string to lower case.
990 ********************************************************************/
992 char *strdup_lower(const char *s)
996 DEBUG(0, ("strdup_lower: Out of memory!\n"));
1003 /*******************************************************************
1004 Convert a string to upper case.
1005 ********************************************************************/
1007 void strupper_m(char *s)
1009 /* this is quite a common operation, so we want it to be
1010 fast. We optimise for the ascii case, knowing that all our
1011 supported multi-byte character sets are ascii-compatible
1012 (ie. they match for the first 128 chars) */
1014 while (*s && !(((unsigned char)s[0]) & 0x7F))
1015 *s++ = toupper((unsigned char)*s);
1020 /* I assume that lowercased string takes the same number of bytes
1021 * as source string even in multibyte encoding. (VIV) */
1022 unix_strupper(s,strlen(s)+1,s,strlen(s)+1);
1025 /*******************************************************************
1026 Convert a string to upper case.
1027 ********************************************************************/
1029 char *strdup_upper(const char *s)
1031 char *t = strdup(s);
1033 DEBUG(0, ("strdup_upper: Out of memory!\n"));
1041 return a RFC2254 binary string representation of a buffer
1042 used in LDAP filters
1045 char *binary_string(char *buf, int len)
1049 const char *hex = "0123456789ABCDEF";
1050 s = malloc(len * 3 + 1);
1053 for (j=i=0;i<len;i++) {
1055 s[j+1] = hex[((unsigned char)buf[i]) >> 4];
1056 s[j+2] = hex[((unsigned char)buf[i]) & 0xF];
1063 /* Just a typesafety wrapper for snprintf into a pstring */
1065 int pstr_sprintf(pstring s, const char *fmt, ...)
1071 ret = vsnprintf(s, PSTRING_LEN, fmt, ap);
1076 /* Just a typesafety wrapper for snprintf into a fstring */
1078 int fstr_sprintf(fstring s, const char *fmt, ...)
1084 ret = vsnprintf(s, FSTRING_LEN, fmt, ap);
1089 #ifndef HAVE_STRNDUP
1090 /*******************************************************************
1091 Some platforms don't have strndup.
1092 ********************************************************************/
1094 char *strndup(const char *s, size_t n)
1109 #ifndef HAVE_STRNLEN
1110 /*******************************************************************
1111 some platforms don't have strnlen
1112 ********************************************************************/
1113 size_t strnlen(const char *s, size_t n)
1116 for (i=0; s[i] && i<n; i++)
1122 /***********************************************************
1123 List of Strings manipulation functions
1124 ***********************************************************/
1126 #define S_LIST_ABS 16 /* List Allocation Block Size */
1128 char **str_list_make(const char *string, const char *sep)
1130 char **list, **rlist;
1135 if (!string || !*string)
1139 DEBUG(0,("str_list_make: Unable to allocate memory"));
1142 if (!sep) sep = LIST_SEP;
1148 while (next_token(&str, tok, sep, sizeof(tok))) {
1150 lsize += S_LIST_ABS;
1151 rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
1153 DEBUG(0,("str_list_make: Unable to allocate memory"));
1154 str_list_free(&list);
1159 memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
1162 list[num] = strdup(tok);
1164 DEBUG(0,("str_list_make: Unable to allocate memory"));
1165 str_list_free(&list);
1177 BOOL str_list_copy(char ***dest, char **src)
1179 char **list, **rlist;
1191 lsize += S_LIST_ABS;
1192 rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
1194 DEBUG(0,("str_list_copy: Unable to allocate memory"));
1195 str_list_free(&list);
1199 memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
1202 list[num] = strdup(src[num]);
1204 DEBUG(0,("str_list_copy: Unable to allocate memory"));
1205 str_list_free(&list);
1216 /* return true if all the elemnts of the list matches exactly */
1218 BOOL str_list_compare(char **list1, char **list2)
1222 if (!list1 || !list2)
1223 return (list1 == list2);
1225 for (num = 0; list1[num]; num++) {
1228 if (!strcsequal(list1[num], list2[num]))
1232 return False; /* if list2 has more elements than list1 fail */
1237 void str_list_free(char ***list)
1241 if (!list || !*list)
1244 for(; *tlist; tlist++)
1249 BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
1252 ssize_t ls, lp, li, ld, i, d;
1261 lp = (ssize_t)strlen(pattern);
1262 li = (ssize_t)strlen(insert);
1267 ls = (ssize_t)strlen(s);
1269 while ((p = strstr(s, pattern))) {
1273 t = (char *) malloc(ls +ld +1);
1275 DEBUG(0,("str_list_substitute: Unable to allocate memory"));
1278 memcpy(t, *list, d);
1279 memcpy(t +d +li, p +lp, ls -d -lp +1);
1286 for (i = 0; i < li; i++) {
1287 switch (insert[i]) {
1299 t[d +i] = insert[i];