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