Sync usage with man page.
[netbsd-mini2440.git] / external / cddl / osnet / sys / kern / string.c
blobf205c45b8416dec0b7f463a5d78ab856a49be950
1 /* $NetBSD: string.c,v 1.1 2009/03/26 22:11:45 ad Exp $ */
3 /*
4 * CDDL HEADER START
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License (the "License").
8 * You may not use this file except in compliance with the License.
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * CDDL HEADER END
24 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #include <sys/param.h>
29 #include <sys/string.h>
31 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
33 #define IS_ALPHA(c) \
34 (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
36 char *
37 strpbrk(const char *s, const char *b)
39 const char *p;
41 do {
42 for (p = b; *p != '\0' && *p != *s; ++p)
44 if (*p != '\0')
45 return ((char *)s);
46 } while (*s++);
48 return (NULL);
52 * Convert a string into a valid C identifier by replacing invalid
53 * characters with '_'. Also makes sure the string is nul-terminated
54 * and takes up at most n bytes.
56 void
57 strident_canon(char *s, size_t n)
59 char c;
60 char *end = s + n - 1;
62 if ((c = *s) == 0)
63 return;
65 if (!IS_ALPHA(c) && c != '_')
66 *s = '_';
68 while (s < end && ((c = *(++s)) != 0)) {
69 if (!IS_ALPHA(c) && !IS_DIGIT(c) && c != '_')
70 *s = '_';
72 *s = 0;