190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2000-2001, 2003 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro * 9266692Sgshapiro * $Id: string.h,v 1.39 2013-11-22 20:51:31 ca Exp $ 1090792Sgshapiro */ 1190792Sgshapiro 1290792Sgshapiro/* 1390792Sgshapiro** libsm string manipulation 1490792Sgshapiro*/ 1590792Sgshapiro 1690792Sgshapiro#ifndef SM_STRING_H 1790792Sgshapiro# define SM_STRING_H 1890792Sgshapiro 1990792Sgshapiro# include <sm/gen.h> 2090792Sgshapiro# include <sm/varargs.h> 2190792Sgshapiro# include <string.h> /* strlc{py,at}, strerror */ 2290792Sgshapiro 2390792Sgshapiro/* return number of bytes left in a buffer */ 2490792Sgshapiro#define SPACELEFT(buf, ptr) (sizeof buf - ((ptr) - buf)) 2590792Sgshapiro 2690792Sgshapiroextern int PRINTFLIKE(3, 4) 27132943Sgshapirosm_snprintf __P((char *, size_t, const char *, ...)); 2890792Sgshapiro 2990792Sgshapiroextern bool 30132943Sgshapirosm_match __P((const char *_str, const char *_pattern)); 3190792Sgshapiro 3290792Sgshapiroextern char * 33132943Sgshapirosm_strdup __P((char *)); 3490792Sgshapiro 3590792Sgshapiroextern char * 36132943Sgshapirosm_strndup_x __P((const char *_str, size_t _len)); 3790792Sgshapiro 38132943Sgshapiro#if DO_NOT_USE_STRCPY 3990792Sgshapiro/* for "normal" data (free'd before end of process) */ 40132943Sgshapiroextern char * 41132943Sgshapirosm_strdup_x __P((const char *_str)); 42132943Sgshapiro 43132943Sgshapiro/* for data that is supposed to be persistent. */ 44132943Sgshapiroextern char * 45132943Sgshapirosm_pstrdup_x __P((const char *_str)); 46132943Sgshapiro 47132943Sgshapiroextern char * 48132943Sgshapirosm_strdup_tagged_x __P((const char *str, char *file, int line, int group)); 49132943Sgshapiro 50132943Sgshapiro#else /* DO_NOT_USE_STRCPY */ 51132943Sgshapiro 52132943Sgshapiro/* for "normal" data (free'd before end of process) */ 5390792Sgshapiro# define sm_strdup_x(str) strcpy(sm_malloc_x(strlen(str) + 1), str) 5490792Sgshapiro 5590792Sgshapiro/* for data that is supposed to be persistent. */ 5690792Sgshapiro# define sm_pstrdup_x(str) strcpy(sm_pmalloc_x(strlen(str) + 1), str) 5790792Sgshapiro 5890792Sgshapiro# define sm_strdup_tagged_x(str, file, line, group) \ 5990792Sgshapiro strcpy(sm_malloc_tagged_x(strlen(str) + 1, file, line, group), str) 60132943Sgshapiro#endif /* DO_NOT_USE_STRCPY */ 6190792Sgshapiro 6290792Sgshapiroextern char * 63132943Sgshapirosm_stringf_x __P((const char *_fmt, ...)); 6490792Sgshapiro 6590792Sgshapiroextern char * 66132943Sgshapirosm_vstringf_x __P((const char *_fmt, va_list _ap)); 6790792Sgshapiro 6890792Sgshapiroextern size_t 69132943Sgshapirosm_strlcpy __P((char *_dst, const char *_src, ssize_t _len)); 7090792Sgshapiro 7190792Sgshapiroextern size_t 72132943Sgshapirosm_strlcat __P((char *_dst, const char *_src, ssize_t _len)); 7390792Sgshapiro 7490792Sgshapiroextern size_t 75132943Sgshapirosm_strlcat2 __P((char *, const char *, const char *, ssize_t)); 7690792Sgshapiro 7790792Sgshapiroextern size_t 7890792Sgshapiro#ifdef __STDC__ 7990792Sgshapirosm_strlcpyn(char *dst, ssize_t len, int n, ...); 8090792Sgshapiro#else /* __STDC__ */ 8190792Sgshapirosm_strlcpyn __P((char *, 8290792Sgshapiro ssize_t, 8390792Sgshapiro int, 8490792Sgshapiro va_dcl)); 8590792Sgshapiro#endif /* __STDC__ */ 8690792Sgshapiro 8790792Sgshapiro# if !HASSTRERROR 8890792Sgshapiroextern char * 89132943Sgshapirostrerror __P((int _errno)); 9090792Sgshapiro# endif /* !HASSTRERROR */ 9190792Sgshapiro 9290792Sgshapiroextern int 93132943Sgshapirosm_strrevcmp __P((const char *, const char *)); 9490792Sgshapiro 9590792Sgshapiroextern int 96132943Sgshapirosm_strrevcasecmp __P((const char *, const char *)); 9790792Sgshapiro 9890792Sgshapiroextern int 99132943Sgshapirosm_strcasecmp __P((const char *, const char *)); 10090792Sgshapiro 10190792Sgshapiroextern int 102132943Sgshapirosm_strncasecmp __P((const char *, const char *, size_t)); 10390792Sgshapiro 10490792Sgshapiroextern LONGLONG_T 105132943Sgshapirosm_strtoll __P((const char *, char**, int)); 10690792Sgshapiro 10790792Sgshapiroextern ULONGLONG_T 108132943Sgshapirosm_strtoull __P((const char *, char**, int)); 10990792Sgshapiro 11090792Sgshapiroextern void 11190792Sgshapirostripquotes __P((char *)); 11290792Sgshapiro 11390792Sgshapiro#endif /* SM_STRING_H */ 114