diff --git a/str.c b/str.c index 496760ab..b572c2d4 100644 --- a/str.c +++ b/str.c @@ -17,6 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include #include #include "str.h" @@ -42,3 +44,11 @@ int strcase_startswith(char *str, const char *substring, char **afterp) return 1; } +/* Like strstr() but doesn't depend on null termination */ +const char *str_str(const char *s1,const char *s2,int s1len) +{ + int s2len=strlen(s2); + for(;*s1&&(s1len--);s1++) + if (!strncmp(s2,s1,s2len)) return s1; + return NULL; +} diff --git a/str.h b/str.h index 7b792700..ee1c3f4d 100644 --- a/str.h +++ b/str.h @@ -37,5 +37,8 @@ int str_startswith(char *str, const char *substring, char **afterp); */ int strcase_startswith(char *str, const char *substring, char **afterp); +/* like strstr(), but doesn't depend on null termination. + @author Paul Gardner-Stephen */ +const char *str_str(const char *s1,const char *s2,int s1len); -#endif \ No newline at end of file +#endif