Open files in binary mode on systems that have O_BINARY
[libtar.git] / compat / strrstr.c
blob097ef9182dd1aba993b21310f48c96ed653a419e
1 /*
2 ** Copyright 1998-2002 University of Illinois Board of Trustees
3 ** Copyright 1998-2002 Mark D. Roth
4 ** All rights reserved.
5 **
6 ** strrstr.c - strrstr() function for compatibility library
7 **
8 ** Mark D. Roth <roth@uiuc.edu>
9 ** Campus Information Technologies and Educational Services
10 ** University of Illinois at Urbana-Champaign
13 #include <stdio.h>
14 #include <sys/types.h>
16 #include <string.h>
20 ** find the last occurrance of find in string
22 char *
23 strrstr(char *string, char *find)
25 size_t stringlen, findlen;
26 char *cp;
28 findlen = strlen(find);
29 stringlen = strlen(string);
30 if (findlen > stringlen)
31 return NULL;
33 for (cp = string + stringlen - findlen; cp >= string; cp--)
34 if (strncmp(cp, find, findlen) == 0)
35 return cp;
37 return NULL;