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