4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/libcfs_string.h
38 * Generic string manipulation functions.
40 * Author: Nathan Rutman <nathan.rutman@sun.com>
43 #ifndef __LIBCFS_STRING_H__
44 #define __LIBCFS_STRING_H__
47 char *cfs_strrstr(const char *haystack, const char *needle);
48 /* Convert a text string to a bitmask */
49 int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
50 int *oldmask, int minmask, int allmask);
53 int cfs_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
56 int cfs_snprintf(char *buf, size_t size, const char *fmt, ...);
58 /* trim leading and trailing space characters */
59 char *cfs_firststr(char *str, size_t size);
62 * Structure to represent NULL-less strings.
70 * Structure to represent \<range_expr\> token of the syntax.
72 struct cfs_range_expr {
74 * Link to cfs_expr_list::el_exprs.
76 struct list_head re_link;
82 struct cfs_expr_list {
83 struct list_head el_link;
84 struct list_head el_exprs;
87 char *cfs_trimwhite(char *str);
88 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
89 int cfs_str2num_check(char *str, int nob, unsigned *num,
90 unsigned min, unsigned max);
91 int cfs_range_expr_parse(struct cfs_lstr *src, unsigned min, unsigned max,
92 int single_tok, struct cfs_range_expr **expr);
93 int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
94 int cfs_expr_list_print(char *buffer, int count,
95 struct cfs_expr_list *expr_list);
96 int cfs_expr_list_values(struct cfs_expr_list *expr_list,
97 int max, __u32 **values);
99 cfs_expr_list_values_free(__u32 *values, int num)
101 /* This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed
102 * by OBD_FREE() if it's called by module other than libcfs & LNet,
103 * otherwise we will see fake memory leak */
104 LIBCFS_FREE(values, num * sizeof(values[0]));
107 void cfs_expr_list_free(struct cfs_expr_list *expr_list);
108 int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
109 struct cfs_expr_list **elpp);
110 void cfs_expr_list_free_list(struct list_head *list);
111 int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
112 int cfs_ip_addr_match(__u32 addr, struct list_head *list);