summaryrefslogtreecommitdiffstats
path: root/Utilities/cmtar/compat/strrstr.c
blob: 8b7f299bb7fc6ff36cdf8c2871343201a16a8612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
**  Copyright 1998-2002 University of Illinois Board of Trustees
**  Copyright 1998-2002 Mark D. Roth
**  All rights reserved.
**
**  strrstr.c - strrstr() function for compatibility library
**
**  Mark D. Roth <roth@uiuc.edu>
**  Campus Information Technologies and Educational Services
**  University of Illinois at Urbana-Champaign
*/

#include <stdio.h>
#include <sys/types.h>

#include <string.h>


/*
** find the last occurrance of find in string
*/
char *
strrstr(char *string, char *find)
{
  size_t stringlen, findlen;
  char *cp;

  findlen = strlen(find);
  stringlen = strlen(string);
  if (findlen > stringlen)
    return NULL;

  for (cp = string + stringlen - findlen; cp >= string; cp--)
    if (strncmp(cp, find, findlen) == 0)
      return cp;

  return NULL;
}