xref: /titanic_41/usr/src/lib/libcommputil/common/commp_util.h (revision 657a8c206b913d1ee578fd725f0b25eca5b77253)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _COMMP_UTIL_H
28 #define	_COMMP_UTIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 
38 #define	COMMP_CRLF			"\r\n"
39 #define	COMMP_LF			"\n"
40 #define	COMMP_SKIP_CRLF(msg_ptr)	((msg_ptr) = (msg_ptr) + 2)
41 #define	COMMP_SKIP_LF(msg_ptr)		((msg_ptr) = (msg_ptr) + 1)
42 
43 #define	COMMP_SECS_IN_DAY		86400
44 #define	COMMP_SECS_IN_HOUR		3600
45 #define	COMMP_SECS_IN_MIN		60
46 
47 #define	COMMP_SP			' '
48 #define	COMMP_CR			'\r'
49 #define	COMMP_COLON			':'
50 #define	COMMP_SLASH			'/'
51 #define	COMMP_EQUALS			'='
52 #define	COMMP_ADDRTYPE_IP4		"IP4"
53 #define	COMMP_ADDRTYPE_IP6		"IP6"
54 
55 #define	COMMP_COPY_STR(dst, src, len) { 		\
56 	(dst) = calloc(1, (len) + 1);			\
57 	if ((dst) != NULL) {				\
58 		(void) strncpy((dst), (src), (len));	\
59 	}						\
60 }
61 
62 extern int	commp_skip_white_space(const char **, const char *);
63 extern int	commp_find_token(const char **, const char **, const char *,
64 		    char, boolean_t);
65 extern int	commp_atoi(const char *, const char *, int *);
66 extern int	commp_strtoull(const char *, const char *, uint64_t *);
67 extern int	commp_strtoub(const char *, const char *, uint8_t *);
68 extern int	commp_atoui(const char *, const char *, uint_t *);
69 extern int	commp_time_to_secs(const char *, const char *, uint64_t *);
70 extern int 	commp_add_str(char **, const char *, int);
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif /* _COMMP_UTIL_H */
77