1*5331Samw /* 2*5331Samw * CDDL HEADER START 3*5331Samw * 4*5331Samw * The contents of this file are subject to the terms of the 5*5331Samw * Common Development and Distribution License (the "License"). 6*5331Samw * You may not use this file except in compliance with the License. 7*5331Samw * 8*5331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5331Samw * or http://www.opensolaris.org/os/licensing. 10*5331Samw * See the License for the specific language governing permissions 11*5331Samw * and limitations under the License. 12*5331Samw * 13*5331Samw * When distributing Covered Code, include this CDDL HEADER in each 14*5331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5331Samw * If applicable, add the following below this CDDL HEADER, with the 16*5331Samw * fields enclosed by brackets "[]" replaced with your own identifying 17*5331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 18*5331Samw * 19*5331Samw * CDDL HEADER END 20*5331Samw */ 21*5331Samw /* 22*5331Samw * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23*5331Samw * Use is subject to license terms. 24*5331Samw */ 25*5331Samw 26*5331Samw /* 27*5331Samw * Implementation of some of the string functions. 28*5331Samw */ 29*5331Samw 30*5331Samw #pragma ident "%Z%%M% %I% %E% SMI" 31*5331Samw 32*5331Samw #ifdef _KERNEL 33*5331Samw #include <sys/types.h> 34*5331Samw #include <sys/sunddi.h> 35*5331Samw #else 36*5331Samw #include <stdlib.h> 37*5331Samw #include <string.h> 38*5331Samw #include <strings.h> 39*5331Samw #endif 40*5331Samw #include <smbsrv/alloc.h> 41*5331Samw #include <smbsrv/string.h> 42*5331Samw #include <smbsrv/ctype.h> 43*5331Samw 44*5331Samw 45*5331Samw /* 46*5331Samw * strsubst 47*5331Samw * 48*5331Samw * Scan a string replacing all occurrences of orgchar with newchar. 49*5331Samw * Returns a pointer to s, or null of s is null. 50*5331Samw */ 51*5331Samw char * 52*5331Samw strsubst(char *s, char orgchar, char newchar) 53*5331Samw { 54*5331Samw char *p = s; 55*5331Samw 56*5331Samw if (p == 0) 57*5331Samw return (0); 58*5331Samw 59*5331Samw while (*p) { 60*5331Samw if (*p == orgchar) 61*5331Samw *p = newchar; 62*5331Samw ++p; 63*5331Samw } 64*5331Samw 65*5331Samw return (s); 66*5331Samw } 67*5331Samw 68*5331Samw /* 69*5331Samw * strcanon 70*5331Samw * 71*5331Samw * Normalize a string by reducing all the repeated characters in 72*5331Samw * buf as defined by class. For example; 73*5331Samw * 74*5331Samw * char *buf = strdup("/d1//d2//d3\\\\d4\\\\f1.txt"); 75*5331Samw * strcanon(buf, "/\\"); 76*5331Samw * 77*5331Samw * Would result in buf containing the following string: 78*5331Samw * 79*5331Samw * /d1/d2/d3\d4\f1.txt 80*5331Samw * 81*5331Samw * This function modifies the contents of buf in place and returns 82*5331Samw * a pointer to buf. 83*5331Samw */ 84*5331Samw char * 85*5331Samw strcanon(char *buf, const char *class) 86*5331Samw { 87*5331Samw char *p = buf; 88*5331Samw char *q = buf; 89*5331Samw char *r; 90*5331Samw 91*5331Samw while (*p) { 92*5331Samw *q++ = *p; 93*5331Samw 94*5331Samw if ((r = strchr(class, *p)) != 0) { 95*5331Samw while (*p == *r) 96*5331Samw ++p; 97*5331Samw } else 98*5331Samw ++p; 99*5331Samw } 100*5331Samw 101*5331Samw *q = '\0'; 102*5331Samw return (buf); 103*5331Samw } 104