string.h revision 132943
1121054Semax/*
2121054Semax * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
3121054Semax *	All rights reserved.
4121054Semax *
5121054Semax * By using this file, you agree to the terms and conditions set
6121054Semax * forth in the LICENSE file which can be found at the top level of
7121054Semax * the sendmail distribution.
8121054Semax *
9121054Semax *	$Id: string.h,v 1.38 2003/10/10 17:56:57 ca Exp $
10195767Skensmith */
11121054Semax
12189462Semax/*
13121054Semax**  libsm string manipulation
14121054Semax*/
15121054Semax
16121054Semax#ifndef SM_STRING_H
17121054Semax# define SM_STRING_H
18121054Semax
19121054Semax# include <sm/gen.h>
20121054Semax# include <sm/varargs.h>
21121054Semax# include <string.h> /* strlc{py,at}, strerror */
22121054Semax
23121054Semax/* return number of bytes left in a buffer */
24121054Semax#define SPACELEFT(buf, ptr)	(sizeof buf - ((ptr) - buf))
25121054Semax
26121054Semaxextern int PRINTFLIKE(3, 4)
27121054Semaxsm_snprintf __P((char *, size_t, const char *, ...));
28121054Semax
29121054Semaxextern bool
30189462Semaxsm_match __P((const char *_str, const char *_pattern));
31189462Semax
32189462Semaxextern char *
33189462Semaxsm_strdup __P((char *));
34189462Semax
35189462Semaxextern char *
36191388Semaxsm_strndup_x __P((const char *_str, size_t _len));
37191388Semax
38191388Semax#if DO_NOT_USE_STRCPY
39191388Semax/* for "normal" data (free'd before end of process) */
40191388Semaxextern char *
41191388Semaxsm_strdup_x __P((const char *_str));
42191388Semax
43191388Semax/* for data that is supposed to be persistent. */
44191388Semaxextern char *
45191388Semaxsm_pstrdup_x __P((const char *_str));
46191388Semax
47191388Semaxextern char *
48191388Semaxsm_strdup_tagged_x __P((const char *str, char *file, int line, int group));
49181698Semax
50181698Semax#else /* DO_NOT_USE_STRCPY */
51181698Semax
52181698Semax/* for "normal" data (free'd before end of process) */
53121054Semax# 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
62extern char *
63sm_stringf_x __P((const char *_fmt, ...));
64
65extern char *
66sm_vstringf_x __P((const char *_fmt, va_list _ap));
67
68extern size_t
69sm_strlcpy __P((char *_dst, const char *_src, ssize_t _len));
70
71extern size_t
72sm_strlcat __P((char *_dst, const char *_src, ssize_t _len));
73
74extern size_t
75sm_strlcat2 __P((char *, const char *, const char *, ssize_t));
76
77extern size_t
78#ifdef __STDC__
79sm_strlcpyn(char *dst, ssize_t len, int n, ...);
80#else /* __STDC__ */
81sm_strlcpyn __P((char *,
82	ssize_t,
83	int,
84	va_dcl));
85#endif /* __STDC__ */
86
87# if !HASSTRERROR
88extern char *
89strerror __P((int _errno));
90# endif /* !HASSTRERROR */
91
92extern int
93sm_strrevcmp __P((const char *, const char *));
94
95extern int
96sm_strrevcasecmp __P((const char *, const char *));
97
98extern int
99sm_strcasecmp __P((const char *, const char *));
100
101extern int
102sm_strncasecmp __P((const char *, const char *, size_t));
103
104extern LONGLONG_T
105sm_strtoll __P((const char *, char**, int));
106
107extern ULONGLONG_T
108sm_strtoull __P((const char *, char**, int));
109
110extern void
111stripquotes __P((char *));
112
113#endif /* SM_STRING_H */
114