Archived
1
0
Fork 0

strbuf.c: use memrchr in strbuf_rchop

This commit is contained in:
Henrik Hautakoski 2010-11-27 18:29:39 +01:00
parent de032e9b33
commit ae3ff5faae
4 changed files with 12 additions and 10 deletions

View file

@ -16,7 +16,7 @@ ifdef DEBUG
endif endif
obj := $(obj-ini) $(obj-log) $(obj-notify) $(obj-path) \ obj := $(obj-ini) $(obj-log) $(obj-notify) $(obj-path) \
$(obj-strbuf) $($obj-xalloc) $(obj-strbuf) $($obj-xalloc) $(obj-compat)
ifeq ($(database), mongo) ifeq ($(database), mongo)
LDFLAGS += -lmongoc -lbson LDFLAGS += -lmongoc -lbson

View file

@ -15,6 +15,9 @@ ifeq ($(VERBOSE), 2)
endif endif
# modules definitions # modules definitions
ifdef NO_MEMRCHR
obj-compat = src/compat/memrchr.o
endif
obj-xalloc = src/xalloc.o src/die.o obj-xalloc = src/xalloc.o src/die.o
obj-strbuf = src/strbuf.o $(obj-xalloc) obj-strbuf = src/strbuf.o $(obj-xalloc)
obj-path = src/path.o $(obj-strbuf) obj-path = src/path.o $(obj-strbuf)

View file

@ -10,3 +10,6 @@
# how to install the libray and header files by yourself. # how to install the libray and header files by yourself.
# database = mysql # database = mysql
# database = mongo # database = mongo
# Uncomment this if you don't have memrchr on your system. (GNU extension as of >=glibc 2.1.91)
# NO_MEMRCHR = 1

View file

@ -9,7 +9,7 @@
*/ */
#include <ctype.h> #include <ctype.h>
#include <string.h> #include "compat/string.h"
#include "xalloc.h" #include "xalloc.h"
#include "strbuf.h" #include "strbuf.h"
@ -111,15 +111,11 @@ void strbuf_append_repeat(strbuf_t *s, char ch, size_t len) {
void strbuf_rchop(strbuf_t *s, char ch) { void strbuf_rchop(strbuf_t *s, char ch) {
int i; char *n = memrchr(s->buf, ch, s->len);
for(i=s->len-1; i >= 0; i--) {
if (s->buf[i] == ch) { if (n) {
s->buf[i] = '\0'; *n = '\0';
s->len = i; s->len = n - s->buf;
break;
}
} }
} }