140266059SGregory Neil Shapiro /* 25dd76dd0SGregory Neil Shapiro * Copyright (c) 2000-2001, 2003 Proofpoint, Inc. and its suppliers. 340266059SGregory Neil Shapiro * All rights reserved. 440266059SGregory Neil Shapiro * 540266059SGregory Neil Shapiro * By using this file, you agree to the terms and conditions set 640266059SGregory Neil Shapiro * forth in the LICENSE file which can be found at the top level of 740266059SGregory Neil Shapiro * the sendmail distribution. 840266059SGregory Neil Shapiro * 94313cc83SGregory Neil Shapiro * $Id: string.h,v 1.39 2013-11-22 20:51:31 ca Exp $ 1040266059SGregory Neil Shapiro */ 1140266059SGregory Neil Shapiro 1240266059SGregory Neil Shapiro /* 1340266059SGregory Neil Shapiro ** libsm string manipulation 1440266059SGregory Neil Shapiro */ 1540266059SGregory Neil Shapiro 1640266059SGregory Neil Shapiro #ifndef SM_STRING_H 1740266059SGregory Neil Shapiro # define SM_STRING_H 1840266059SGregory Neil Shapiro 1940266059SGregory Neil Shapiro # include <sm/gen.h> 2040266059SGregory Neil Shapiro # include <sm/varargs.h> 2140266059SGregory Neil Shapiro # include <string.h> /* strlc{py,at}, strerror */ 2240266059SGregory Neil Shapiro 2340266059SGregory Neil Shapiro /* return number of bytes left in a buffer */ 2440266059SGregory Neil Shapiro #define SPACELEFT(buf, ptr) (sizeof buf - ((ptr) - buf)) 2540266059SGregory Neil Shapiro 2640266059SGregory Neil Shapiro extern int PRINTFLIKE(3, 4) 27e92d3f3fSGregory Neil Shapiro sm_snprintf __P((char *, size_t, const char *, ...)); 2840266059SGregory Neil Shapiro 2940266059SGregory Neil Shapiro extern bool 30e92d3f3fSGregory Neil Shapiro sm_match __P((const char *_str, const char *_pattern)); 3140266059SGregory Neil Shapiro 3240266059SGregory Neil Shapiro extern char * 33*5b0945b5SGregory Neil Shapiro sm_strdup __P((const char *)); 3440266059SGregory Neil Shapiro 3540266059SGregory Neil Shapiro extern char * 36e92d3f3fSGregory Neil Shapiro sm_strndup_x __P((const char *_str, size_t _len)); 37e92d3f3fSGregory Neil Shapiro 38e92d3f3fSGregory Neil Shapiro #if DO_NOT_USE_STRCPY 39e92d3f3fSGregory Neil Shapiro /* for "normal" data (free'd before end of process) */ 40e92d3f3fSGregory Neil Shapiro extern char * 41e92d3f3fSGregory Neil Shapiro sm_strdup_x __P((const char *_str)); 42e92d3f3fSGregory Neil Shapiro 43e92d3f3fSGregory Neil Shapiro /* for data that is supposed to be persistent. */ 44e92d3f3fSGregory Neil Shapiro extern char * 45e92d3f3fSGregory Neil Shapiro sm_pstrdup_x __P((const char *_str)); 46e92d3f3fSGregory Neil Shapiro 47e92d3f3fSGregory Neil Shapiro extern char * 48e92d3f3fSGregory Neil Shapiro sm_strdup_tagged_x __P((const char *str, char *file, int line, int group)); 49e92d3f3fSGregory Neil Shapiro 50e92d3f3fSGregory Neil Shapiro #else /* DO_NOT_USE_STRCPY */ 5140266059SGregory Neil Shapiro 5240266059SGregory Neil Shapiro /* for "normal" data (free'd before end of process) */ 5340266059SGregory Neil Shapiro # define sm_strdup_x(str) strcpy(sm_malloc_x(strlen(str) + 1), str) 5440266059SGregory Neil Shapiro 5540266059SGregory Neil Shapiro /* for data that is supposed to be persistent. */ 5640266059SGregory Neil Shapiro # define sm_pstrdup_x(str) strcpy(sm_pmalloc_x(strlen(str) + 1), str) 5740266059SGregory Neil Shapiro 5840266059SGregory Neil Shapiro # define sm_strdup_tagged_x(str, file, line, group) \ 5940266059SGregory Neil Shapiro strcpy(sm_malloc_tagged_x(strlen(str) + 1, file, line, group), str) 60e92d3f3fSGregory Neil Shapiro #endif /* DO_NOT_USE_STRCPY */ 6140266059SGregory Neil Shapiro 6240266059SGregory Neil Shapiro extern char * 63e92d3f3fSGregory Neil Shapiro sm_stringf_x __P((const char *_fmt, ...)); 6440266059SGregory Neil Shapiro 6540266059SGregory Neil Shapiro extern char * 66e92d3f3fSGregory Neil Shapiro sm_vstringf_x __P((const char *_fmt, va_list _ap)); 6740266059SGregory Neil Shapiro 6840266059SGregory Neil Shapiro extern size_t 69e92d3f3fSGregory Neil Shapiro sm_strlcpy __P((char *_dst, const char *_src, ssize_t _len)); 7040266059SGregory Neil Shapiro 7140266059SGregory Neil Shapiro extern size_t 72e92d3f3fSGregory Neil Shapiro sm_strlcat __P((char *_dst, const char *_src, ssize_t _len)); 7340266059SGregory Neil Shapiro 7440266059SGregory Neil Shapiro extern size_t 75e92d3f3fSGregory Neil Shapiro sm_strlcat2 __P((char *, const char *, const char *, ssize_t)); 7640266059SGregory Neil Shapiro 7740266059SGregory Neil Shapiro extern size_t 7840266059SGregory Neil Shapiro #ifdef __STDC__ 7940266059SGregory Neil Shapiro sm_strlcpyn(char *dst, ssize_t len, int n, ...); 8040266059SGregory Neil Shapiro #else /* __STDC__ */ 8140266059SGregory Neil Shapiro sm_strlcpyn __P((char *, 8240266059SGregory Neil Shapiro ssize_t, 8340266059SGregory Neil Shapiro int, 8440266059SGregory Neil Shapiro va_dcl)); 8540266059SGregory Neil Shapiro #endif /* __STDC__ */ 8640266059SGregory Neil Shapiro 8740266059SGregory Neil Shapiro # if !HASSTRERROR 8840266059SGregory Neil Shapiro extern char * 89e92d3f3fSGregory Neil Shapiro strerror __P((int _errno)); 90*5b0945b5SGregory Neil Shapiro # endif 9140266059SGregory Neil Shapiro 9240266059SGregory Neil Shapiro extern int 93e92d3f3fSGregory Neil Shapiro sm_strrevcmp __P((const char *, const char *)); 9440266059SGregory Neil Shapiro 9540266059SGregory Neil Shapiro extern int 96e92d3f3fSGregory Neil Shapiro sm_strrevcasecmp __P((const char *, const char *)); 9740266059SGregory Neil Shapiro 9840266059SGregory Neil Shapiro extern int 99e92d3f3fSGregory Neil Shapiro sm_strcasecmp __P((const char *, const char *)); 10040266059SGregory Neil Shapiro 10140266059SGregory Neil Shapiro extern int 102e92d3f3fSGregory Neil Shapiro sm_strncasecmp __P((const char *, const char *, size_t)); 10340266059SGregory Neil Shapiro 10440266059SGregory Neil Shapiro extern LONGLONG_T 105e92d3f3fSGregory Neil Shapiro sm_strtoll __P((const char *, char**, int)); 10640266059SGregory Neil Shapiro 10740266059SGregory Neil Shapiro extern ULONGLONG_T 108e92d3f3fSGregory Neil Shapiro sm_strtoull __P((const char *, char**, int)); 10940266059SGregory Neil Shapiro 11040266059SGregory Neil Shapiro extern void 11140266059SGregory Neil Shapiro stripquotes __P((char *)); 112*5b0945b5SGregory Neil Shapiro extern void 113*5b0945b5SGregory Neil Shapiro unfoldstripquotes __P((char *)); 11440266059SGregory Neil Shapiro 11540266059SGregory Neil Shapiro #endif /* SM_STRING_H */ 116