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