1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  *	$Id: string.h,v 1.38 2003/10/10 17:56:57 ca Exp $
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate /*
13*7c478bd9Sstevel@tonic-gate **  libsm string manipulation
14*7c478bd9Sstevel@tonic-gate */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #ifndef SM_STRING_H
17*7c478bd9Sstevel@tonic-gate # define SM_STRING_H
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate # include <sm/gen.h>
20*7c478bd9Sstevel@tonic-gate # include <sm/varargs.h>
21*7c478bd9Sstevel@tonic-gate # include <string.h> /* strlc{py,at}, strerror */
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate /* return number of bytes left in a buffer */
24*7c478bd9Sstevel@tonic-gate #define SPACELEFT(buf, ptr)	(sizeof buf - ((ptr) - buf))
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate extern int PRINTFLIKE(3, 4)
27*7c478bd9Sstevel@tonic-gate sm_snprintf __P((char *, size_t, const char *, ...));
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate extern bool
30*7c478bd9Sstevel@tonic-gate sm_match __P((const char *_str, const char *_pattern));
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate extern char *
33*7c478bd9Sstevel@tonic-gate sm_strdup __P((char *));
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate extern char *
36*7c478bd9Sstevel@tonic-gate sm_strndup_x __P((const char *_str, size_t _len));
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #if DO_NOT_USE_STRCPY
39*7c478bd9Sstevel@tonic-gate /* for "normal" data (free'd before end of process) */
40*7c478bd9Sstevel@tonic-gate extern char *
41*7c478bd9Sstevel@tonic-gate sm_strdup_x __P((const char *_str));
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /* for data that is supposed to be persistent. */
44*7c478bd9Sstevel@tonic-gate extern char *
45*7c478bd9Sstevel@tonic-gate sm_pstrdup_x __P((const char *_str));
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate extern char *
48*7c478bd9Sstevel@tonic-gate sm_strdup_tagged_x __P((const char *str, char *file, int line, int group));
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #else /* DO_NOT_USE_STRCPY */
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /* for "normal" data (free'd before end of process) */
53*7c478bd9Sstevel@tonic-gate # define sm_strdup_x(str) strcpy(sm_malloc_x(strlen(str) + 1), str)
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /* for data that is supposed to be persistent. */
56*7c478bd9Sstevel@tonic-gate # define sm_pstrdup_x(str) strcpy(sm_pmalloc_x(strlen(str) + 1), str)
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate # define sm_strdup_tagged_x(str, file, line, group) \
59*7c478bd9Sstevel@tonic-gate 	strcpy(sm_malloc_tagged_x(strlen(str) + 1, file, line, group), str)
60*7c478bd9Sstevel@tonic-gate #endif /* DO_NOT_USE_STRCPY */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate extern char *
63*7c478bd9Sstevel@tonic-gate sm_stringf_x __P((const char *_fmt, ...));
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate extern char *
66*7c478bd9Sstevel@tonic-gate sm_vstringf_x __P((const char *_fmt, va_list _ap));
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate extern size_t
69*7c478bd9Sstevel@tonic-gate sm_strlcpy __P((char *_dst, const char *_src, ssize_t _len));
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate extern size_t
72*7c478bd9Sstevel@tonic-gate sm_strlcat __P((char *_dst, const char *_src, ssize_t _len));
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate extern size_t
75*7c478bd9Sstevel@tonic-gate sm_strlcat2 __P((char *, const char *, const char *, ssize_t));
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate extern size_t
78*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
79*7c478bd9Sstevel@tonic-gate sm_strlcpyn(char *dst, ssize_t len, int n, ...);
80*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */
81*7c478bd9Sstevel@tonic-gate sm_strlcpyn __P((char *,
82*7c478bd9Sstevel@tonic-gate 	ssize_t,
83*7c478bd9Sstevel@tonic-gate 	int,
84*7c478bd9Sstevel@tonic-gate 	va_dcl));
85*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate # if !HASSTRERROR
88*7c478bd9Sstevel@tonic-gate extern char *
89*7c478bd9Sstevel@tonic-gate strerror __P((int _errno));
90*7c478bd9Sstevel@tonic-gate # endif /* !HASSTRERROR */
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate extern int
93*7c478bd9Sstevel@tonic-gate sm_strrevcmp __P((const char *, const char *));
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate extern int
96*7c478bd9Sstevel@tonic-gate sm_strrevcasecmp __P((const char *, const char *));
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate extern int
99*7c478bd9Sstevel@tonic-gate sm_strcasecmp __P((const char *, const char *));
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate extern int
102*7c478bd9Sstevel@tonic-gate sm_strncasecmp __P((const char *, const char *, size_t));
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate extern LONGLONG_T
105*7c478bd9Sstevel@tonic-gate sm_strtoll __P((const char *, char**, int));
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate extern ULONGLONG_T
108*7c478bd9Sstevel@tonic-gate sm_strtoull __P((const char *, char**, int));
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate extern void
111*7c478bd9Sstevel@tonic-gate stripquotes __P((char *));
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate #endif /* SM_STRING_H */
114