Annotation of GNUtools/libg++/libiberty/strstr.c, revision 1.1.1.1

1.1       root        1: /* Simple implementation of strstr for systems without it.
                      2:    Copyright (C) 1991 Free Software Foundation, Inc.
                      3: 
                      4: This file is part of the libiberty library.
                      5: Libiberty is free software; you can redistribute it and/or
                      6: modify it under the terms of the GNU Library General Public
                      7: License as published by the Free Software Foundation; either
                      8: version 2 of the License, or (at your option) any later version.
                      9: 
                     10: Libiberty is distributed in the hope that it will be useful,
                     11: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     13: Library General Public License for more details.
                     14: 
                     15: You should have received a copy of the GNU Library General Public
                     16: License along with libiberty; see the file COPYING.LIB.  If
                     17: not, write to the Free Software Foundation, Inc., 675 Mass Ave,
                     18: Cambridge, MA 02139, USA.  */
                     19: 
                     20: /*
                     21: 
                     22: NAME
                     23: 
                     24:        strstr -- locate first occurance of a substring
                     25: 
                     26: SYNOPSIS
                     27: 
                     28:        #include <string.h>
                     29: 
                     30:        char *strstr (char *s1, char *s2)
                     31: 
                     32: DESCRIPTION
                     33: 
                     34:        Locates the first occurance in the string pointed to by S1 of
                     35:        the string pointed to by S2.  Returns a pointer to the substring
                     36:        found, or a NULL pointer if not found.  If S2 points to a string
                     37:        with zero length, the function returns S1.
                     38:        
                     39: BUGS
                     40: 
                     41: */
                     42: 
                     43: 
                     44: /* FIXME:  The above description is ANSI compiliant.  This routine has not
                     45:    been validated to comply with it.  -fnf */
                     46: 
                     47: char *
                     48: strstr (s1, s2)
                     49:   char *s1, *s2;
                     50: {
                     51:   register char *p = s1;
                     52:   extern char *strchr ();
                     53:   extern int strncmp ();
                     54: #if __GNUC__==2
                     55:   extern __SIZE_TYPE__ strlen ();
                     56: #endif
                     57:   register int len = strlen (s2);
                     58: 
                     59:   for (; (p = strchr (p, *s2)) != 0; p++)
                     60:     {
                     61:       if (strncmp (p, s2, len) == 0)
                     62:        {
                     63:          return (p);
                     64:        }
                     65:     }
                     66:   return (0);
                     67: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.