annotate 3rdparty/packages/uucpbb/src/strstr.c @ 3295:6b7a7b233925 default tip

makefile: Allow PORTS with level1/2 mix https://sourceforge.net/p/nitros9/feature-requests/10/
author Tormod Volden <debian.tormod@gmail.com>
date Tue, 19 Apr 2022 18:12:17 +0200
parents 5ba8e711a1a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1772
5ba8e711a1a3 source added
boisy
parents:
diff changeset
1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
2 This file is part of the GNU C Library.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
3
5ba8e711a1a3 source added
boisy
parents:
diff changeset
4 The GNU C Library is free software; you can redistribute it and/or
5ba8e711a1a3 source added
boisy
parents:
diff changeset
5 modify it under the terms of the GNU Library General Public License as
5ba8e711a1a3 source added
boisy
parents:
diff changeset
6 published by the Free Software Foundation; either version 2 of the
5ba8e711a1a3 source added
boisy
parents:
diff changeset
7 License, or (at your option) any later version.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
8
5ba8e711a1a3 source added
boisy
parents:
diff changeset
9 The GNU C Library is distributed in the hope that it will be useful,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
5ba8e711a1a3 source added
boisy
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ba8e711a1a3 source added
boisy
parents:
diff changeset
12 Library General Public License for more details.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
13
5ba8e711a1a3 source added
boisy
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
5ba8e711a1a3 source added
boisy
parents:
diff changeset
15 License along with the GNU C Library; see the file COPYING.LIB. If
5ba8e711a1a3 source added
boisy
parents:
diff changeset
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
5ba8e711a1a3 source added
boisy
parents:
diff changeset
17 Cambridge, MA 02139, USA.
5ba8e711a1a3 source added
boisy
parents:
diff changeset
18
5ba8e711a1a3 source added
boisy
parents:
diff changeset
19 This file was modified by Bob Billson, March, 1994 for the OS-9 UUCP package
5ba8e711a1a3 source added
boisy
parents:
diff changeset
20 UUCPbb. */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
21
5ba8e711a1a3 source added
boisy
parents:
diff changeset
22 #ifndef _UCC /* Ultra C already has strstr() */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
23 #include "uucp.h"
5ba8e711a1a3 source added
boisy
parents:
diff changeset
24
5ba8e711a1a3 source added
boisy
parents:
diff changeset
25 /* Return the first ocurrence of NEEDLE in HAYSTACK. */
5ba8e711a1a3 source added
boisy
parents:
diff changeset
26
5ba8e711a1a3 source added
boisy
parents:
diff changeset
27 char *strstr (haystack, needle)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
28 char *haystack, *needle;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
29 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
30 register char *begin;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
31 char *end_needle = strend (needle);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
32 char *end_haystack = strend (haystack);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
33 int len_needle = end_needle - needle;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
34 int last_needle = len_needle - 1;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
35
5ba8e711a1a3 source added
boisy
parents:
diff changeset
36 if (len_needle == 0)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
37 return ((char *) end_haystack);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
38
5ba8e711a1a3 source added
boisy
parents:
diff changeset
39 if ((end_haystack - haystack) < len_needle)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
40 return (NULL);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
41
5ba8e711a1a3 source added
boisy
parents:
diff changeset
42 for (begin = &haystack[last_needle]; begin < end_haystack; ++begin)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
43 {
5ba8e711a1a3 source added
boisy
parents:
diff changeset
44 char *n = &needle[last_needle];
5ba8e711a1a3 source added
boisy
parents:
diff changeset
45 char *h = begin;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
46
5ba8e711a1a3 source added
boisy
parents:
diff changeset
47 do
5ba8e711a1a3 source added
boisy
parents:
diff changeset
48 if (*h != *n)
5ba8e711a1a3 source added
boisy
parents:
diff changeset
49 goto loop;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
50 while (--n >= needle && --h >= haystack);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
51
5ba8e711a1a3 source added
boisy
parents:
diff changeset
52 return ((char *) h);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
53 loop: ;
5ba8e711a1a3 source added
boisy
parents:
diff changeset
54 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
55 return (NULL);
5ba8e711a1a3 source added
boisy
parents:
diff changeset
56 }
5ba8e711a1a3 source added
boisy
parents:
diff changeset
57 #endif