strbuf.c: use memrchr in strbuf_rchop
This commit is contained in:
parent
de032e9b33
commit
ae3ff5faae
4 changed files with 12 additions and 10 deletions
2
Makefile
2
Makefile
|
|
@ -16,7 +16,7 @@ ifdef DEBUG
|
|||
endif
|
||||
|
||||
obj := $(obj-ini) $(obj-log) $(obj-notify) $(obj-path) \
|
||||
$(obj-strbuf) $($obj-xalloc)
|
||||
$(obj-strbuf) $($obj-xalloc) $(obj-compat)
|
||||
|
||||
ifeq ($(database), mongo)
|
||||
LDFLAGS += -lmongoc -lbson
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ ifeq ($(VERBOSE), 2)
|
|||
endif
|
||||
|
||||
# modules definitions
|
||||
ifdef NO_MEMRCHR
|
||||
obj-compat = src/compat/memrchr.o
|
||||
endif
|
||||
obj-xalloc = src/xalloc.o src/die.o
|
||||
obj-strbuf = src/strbuf.o $(obj-xalloc)
|
||||
obj-path = src/path.o $(obj-strbuf)
|
||||
|
|
|
|||
|
|
@ -10,3 +10,6 @@
|
|||
# how to install the libray and header files by yourself.
|
||||
# database = mysql
|
||||
# database = mongo
|
||||
|
||||
# Uncomment this if you don't have memrchr on your system. (GNU extension as of >=glibc 2.1.91)
|
||||
# NO_MEMRCHR = 1
|
||||
|
|
|
|||
14
src/strbuf.c
14
src/strbuf.c
|
|
@ -9,7 +9,7 @@
|
|||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "compat/string.h"
|
||||
#include "xalloc.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) {
|
||||
|
||||
int i;
|
||||
char *n = memrchr(s->buf, ch, s->len);
|
||||
|
||||
for(i=s->len-1; i >= 0; i--) {
|
||||
|
||||
if (s->buf[i] == ch) {
|
||||
s->buf[i] = '\0';
|
||||
s->len = i;
|
||||
break;
|
||||
}
|
||||
if (n) {
|
||||
*n = '\0';
|
||||
s->len = n - s->buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue