This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
strrstr
- From: Reuben Thomas <rrt at sc3d dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 30 Apr 2008 20:33:46 +0100 (BST)
- Subject: strrstr
Hi,
I note that glibc has no strrstr implementation, and I can't after a bit of
searching find anything saying that there's no desire to have this
widely-used and implemented function.
I have written an original implementation which I use in GNU Zile, and which
has therefore already had its copyright assigned to the FSF. It was written
for correctness and simplicity, and has been in production use in Zile for
some years, although at present it has no test suite. Here it is:
#include <stddef.h>
#include <string.h>
char *strrstr (const char *s, const char *t);
char *
strrstr (const char *s, const char *t)
{
size_t i, j, tlen = strlen (t);
for (i = strlen (s); i >= tlen; i--)
{
for (j = 0; j < tlen && s[i - tlen + j] == t[j]; j++)
;
if (j == tlen)
return (char *) (s + i - tlen);
}
return NULL;
}
Would it be any use for glibc? glibc's one of the most widely-deployed C
libraries that still lacks this function.
--
http://rrt.sc3d.org/ | resident, a. unable to leave (Bierce)