strstr.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* strstr - find first occurrence of wanted in s
  2. Copyright (C) 1989, Free Software Foundation.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #define CONST
  16. #define SIZET int
  17. #define NULL 0
  18. char * /* found string, or NULL if none */
  19. strstr(s, wanted)
  20. CONST char *s;
  21. CONST char *wanted;
  22. {
  23. register CONST char *scan;
  24. register SIZET len;
  25. register char firstc;
  26. extern int strcmp();
  27. extern SIZET strlen();
  28. /*
  29. * The odd placement of the two tests is so "" is findable.
  30. * Also, we inline the first char for speed.
  31. * The ++ on scan has been moved down for optimization.
  32. */
  33. firstc = *wanted;
  34. len = strlen(wanted);
  35. for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
  36. if (*scan++ == '\0')
  37. return(NULL);
  38. return(scan);
  39. }