Whamcloud - gitweb
LU-6245 libcfs: create userland and kernel string operations
[fs/lustre-release.git] / libcfs / include / libcfs / util / string.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * libcfs/include/libcfs/libcfs_string.h
37  *
38  * Generic string manipulation functions.
39  *
40  * Author: Nathan Rutman <nathan.rutman@sun.com>
41  */
42
43 #ifndef __LIBCFS_UTIL_STRING_H__
44 #define __LIBCFS_UTIL_STRING_H__
45
46 #include <stddef.h>
47
48 #include <linux/types.h>
49 #include <libcfs/list.h>
50
51 #ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
52 size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
53 #endif
54
55 #ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
56 size_t strlcat(char *tgt, const char *src, size_t tgt_len);
57 #endif
58
59 /**
60  * Structure to represent NULL-less strings.
61  */
62 struct cfs_lstr {
63         char            *ls_str;
64         int             ls_len;
65 };
66
67 /*
68  * Structure to represent \<range_expr\> token of the syntax.
69  */
70 struct cfs_range_expr {
71         /*
72          * Link to cfs_expr_list::el_exprs.
73          */
74         struct list_head        re_link;
75         __u32                   re_lo;
76         __u32                   re_hi;
77         __u32                   re_stride;
78 };
79
80 struct cfs_expr_list {
81         struct list_head        el_link;
82         struct list_head        el_exprs;
83 };
84
85 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
86 int cfs_str2num_check(char *str, int nob, unsigned *num,
87                       unsigned min, unsigned max);
88 int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
89 int cfs_expr_list_print(char *buffer, int count,
90                         struct cfs_expr_list *expr_list);
91 int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
92                         struct cfs_expr_list **elpp);
93 void cfs_expr_list_free_list(struct list_head *list);
94 int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
95 int cfs_ip_addr_match(__u32 addr, struct list_head *list);
96
97 #endif