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