This is Vladimir's update to last_char_is(). Since 'char *' is
authorEric Andersen <andersen@codepoet.org>
Mon, 7 May 2001 23:10:16 +0000 (23:10 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 7 May 2001 23:10:16 +0000 (23:10 -0000)
the least common denominator, I modified it to use that (not const),
which will minimize the need for casting elsewhere.

libbb/last_char_is.c

index b4bb7ec32fad30cbae5177498d6e3653a787af92..36b695b40af3136a6135efcf013a11702f51b02f 100644 (file)
  * underrun the buffer if the string length is 0.  Also avoids a possible
  * space-hogging inline of strlen() per usage.
  */
-int last_char_is(const char *s, const int c)
+char * last_char_is(char *s, int c)
 {
-       int  l = strlen(s);
-       if (l==0) return 0;
-       return (s[l-1] == c);
+       char *sret  = s+strlen(s)-1;
+       if (sret>=s && *sret == c) { 
+               return sret;
+       } else {
+               return NULL;
+       }
 }